[#ftl]
[#assign cmp0 =1]
[#assign GenerateNvicEnable = false]
[#-- macro generateConfigModelCode --]

[#macro generateConfigModelCode configModel inst nTab index mode]
[#if configModel.clockEnableMacro?? && mode=="Init"] [#-- Enable Port clock --]
    [#list configModel.clockEnableMacro as clkmacroList]
        [#if clkmacroList?trim!=""]
            [#if nTab==2]#t#t[#else]#t[/#if]${clkmacroList}[#if !clkmacroList?contains("(")]()[/#if];
        [/#if]
    [/#list]
[/#if] 
[#if configModel.methods??] [#-- if the pin configuration contains a list of LibMethods--]
    [#assign methodList = configModel.methods]
[#else]
    [#if configModel.methods??]
        [#assign methodList = configModel.libMethod]  
    [/#if]
[/#if]
[#assign writeConfigComments=false]
[#if methodList?? ]
[#list methodList as method]
    [#if method.status=="OK"][#assign writeConfigComments=true][/#if]
[/#list]
[#if writeConfigComments]
    [#if configModel.comments??]
        [#if nTab == 2]#t[/#if][#if nTab == 2]#t/**${configModel.comments?replace("#t","#t#t")}#n#t#t*/[#else]#t/**${configModel.comments?replace("#t","#t")}#n#t*/[/#if]

    [/#if]
[/#if]
    [#list methodList as method][#assign args = ""]
            [#if method.hardCode??] [#-- Hard code --]
                ${method.hardCode.text?replace("$IpInstance",inst)} 
            [#else]
                [#if method.type == "Template"] [#-- Template code --]  
                    [#list method.name?split("/") as n]
                        [#assign tplName = n]
                    [/#list]
                    [@optinclude name=mxTmpFolder+"/${tplName?replace('ftl','tmp')}" /] 
                [/#if]
            [/#if]
            [#if method.status=="OK" && method.type != "Template" && method.type != "HardCode"]
[#if method.comment??]
[/#if]
                [#if method.arguments??]
                    [#list method.arguments as fargument][#compress]
                    [#if fargument.addressOf] [#assign adr = "&"][#else ][#assign adr = ""][/#if]
                    [#if fargument.cast??] [#assign adr = fargument.cast + adr][/#if]
                    [/#compress]
                    [#if fargument.genericType == "struct"]
                         [#if fargument.optional == "output"]
                                [#assign arg = "" + adr + fargument.name]
                                [#if fargument.cast??] [#assign arg = fargument.cast + arg][/#if]
                        [/#if]
                        [#if fargument.context?? && fargument.optional!="output"]
                            [#if fargument.context=="global"]
                                [#if configModel.ipName=="DMA" || configModel.ipName=="BDMA"]
                                    [#assign instanceIndex = "_"+ configModel.dmaRequestName?lower_case]
                                [#else]
                                   [#if configModel.ipName?starts_with("GPDMA") || configModel.ipName?starts_with("LPDMA")]
                                        [#assign instanceIndex = ""]
                                   [#else]
                                        [#-- [#assign instanceIndex = inst?replace(name,"")]--]
                                        [#if index??][#assign instanceIndex = index][#else][#if name??][#assign instanceIndex = inst?replace(name,"")][/#if][/#if]
                                        [#if configModel.ipName=="DFSDM" || configModel.ipName=="MDF" || configModel.ipName=="ADF"]
                                             [#assign instanceIndex = ""]
                                        [/#if]
                                   [/#if]
                                [/#if]
                            [/#if]
                        [/#if]
                        [#if instanceIndex??&&fargument.context=="global"][#if fargument.status!="NULL"][#assign arg = "" + adr + fargument.name + instanceIndex][#else][#assign arg = "NULL"][/#if][#else][#if  fargument.status!="NULL"][#assign arg = "" + adr + fargument.name][#else][#assign arg = "NULL"][/#if][/#if]
                        [#-- [#assign arg = "" + adr + fargument.name] --]
                        [#if ((!method.name?contains("Init")&&fargument.context=="global")||(fargument.optional=="output"))]
                        [#else]
                        [#list fargument.argument as argument]
                            [#if argument.genericType != "struct"]
                                [#if argument.mandatory]
                                [#if argument.value?? && argument.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global"]
                                        [#assign argValue=argument.value?replace("$Index",instanceIndex)]
                                    [#else]
                                        [#assign argValue=argument.value]
                                    [/#if][#-- if global --]
                                    [#if argument.genericType=="Array" && argument.context!="globalConst" && argument.context!="globalInit"][#-- if genericType=Array --]
                                    [#assign valList = argument.value?split(argument.arraySeparator)]     
                                            [#assign i = 0]                                  
                                        [#list valList as val] 
                                            #t${argument.name}[${i}] = ${val};
                                            [#assign i = i+1]
                                        [/#list]
                                        [#assign argValue="&"+argument.name]
                                    [/#if] [#-- if genericType=Array --]
                                    [#-- if argument is a global array --]
                                    [#if argument.genericType=="Array" && (argument.context=="globalConst"|| argument.context=="globalInit")][#-- if genericType=Array and gloabl--]                                        
                                        [#assign argValue="("+argument.typeName +" *)"+argument.name]
                                    [/#if]
                                    [#if argument.value!="" && argument.value!="N/A"]
                                    [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = ${argValue};
                                    [#else]
                                    [#if nTab==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = [#if argument.value!="N/A"]${argValue}[/#if];
                                    [/#if]                                                                     
                                    [/#if]
                                    [#else] [#-- else argument.mandatory--]
                                      [#if fargument.name!="GPIO_InitStruct" && fargument.name!="GPIO_Init"]
                                            [#if argument.name=="Instance"][#-- if argument=Instance--]
                                              [#-- calculate the value of Instance argument if contains $Index --]
                                                [#if  (argument.value?? && argument.value!="__NULL") && (argument.value?contains("$Index"))]
                                                    [#assign instanceValue=argument.value?replace("$Index",index)]
                                                [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = ${instanceValue};
                                                [#else]
                                                   [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = [#if argument.value?? && argument.value!="__NULL"]${argument.value};[#else]${inst};[/#if]
                                                [/#if]
                                          [#else]
                                              [#if argument.status=="KO"]
                                                   [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]//${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = ${argument.value};                                        
                                              [/#if]
                                              [#if argument.value?? && argument.value!="__NULL"]
                                                   [#if argument.value!="N/A"][#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = ${argument.value};  [/#if]
                                              [/#if]                                    
                                          [/#if][#-- if argument=Instance--]                                
                                      [/#if]    
                                [/#if][#-- if argument.mandatory--]                                
                            [#else]
                            [#list argument.argument as argument2]
[#if argument2.genericType!="struct"]
                                [#if argument2.value?? && argument2.value!="__NULL"][#assign argValue=argument2.value][#else] [#assign argValue=""][/#if]
                                [#if argument2.mandatory]
                                    [#if argument2.value?? && argument2.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global"][#assign argValue=argument2.value?replace("$Index",instanceIndex)][#else][#assign argValue=argument2.value][/#if]
                                    [#if argument2.genericType=="Array" && argument2.context!="globalConst" && argument2.context!="globalInit"][#-- if genericType=Array --]
                                        [#if argument2.arraySeparator?? && argument2.arraySeparator!=""]
                                        [#assign valList = argument2.value?split(argument2.arraySeparator)]     
                                        [#else]
                                            [#assign valList = argument2.value?split(":")]
                                        [/#if]    
                                            [#assign i = 0]                                  
                                        [#list valList as val] 
                                            #t${argument2.name}[${i}] = ${val};
                                            [#assign i = i+1]
                                        [/#list]
                                        [#assign argValue="&"+argument2.name+"[0]"]
                                    [/#if] [#-- if genericType=Array --]
                                    [#-- if argument is a global array --]
                                    [#if argument2.genericType=="Array" && (argument2.context=="globalConst" || argument2.context=="globalInit")][#-- if genericType=Array and gloabl--]                                        
                                        [#assign argValue="("+argument2.typeName +" *)"+argument2.name]
                                    [/#if]
                                    [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name} = ${argValue};                                    
                                    [/#if]
                               [#else] [#-- !argument.mandatory --]
                                    [#if argument2.status=="KO"]
                                        [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]//${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name} = ${argValue};
                                    [/#if]
                                    [#if argument2.status=="OK"]
                                    [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name} = ${argValue};
                                    [/#if]
                                [/#if][#-- if argument.mandatory --]
[#else]
[#list argument2.argument as argument3]
 [#if argument3.value?? && argument3.value!="__NULL"][#assign argValue=argument3.value][#else] [#assign argValue=""][/#if]
                                [#if argument3.mandatory]
                                    [#if argument3.value?? && argument3.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global"][#assign argValue=argument3.value?replace("$Index",instanceIndex)][#else][#assign argValue=argument3.value][/#if]
                                    [#if argument3.genericType=="Array" && argument3.context!="globalConst" && argument3.context!="globalInit"][#-- if genericType=Array --] 
                                        [#if argument3.arraySeparator?? && argument3.arraySeparator!=""]
                                            [#assign valList = argument3.value?split(argument3.arraySeparator)]     
                                        [#else]
                                            [#assign valList = argument3.value?split(":")]
                                        [/#if]     
                                            [#assign i = 0]                                  
                                        [#list valList as val] 
                                            #t${argument3.name}[${i}] = ${val};
                                            [#assign i = i+1]
                                        [/#list]
                                        [#assign argValue="&"+argument3.name+"[0]"]
                                    [/#if] [#-- if genericType=Array --]
                                    [#-- if argument is a global array --]
                                    [#if argument3.genericType=="Array" && (argument3.context=="globalConst" || argument3.context=="globalInit")][#-- if genericType=Array and gloabl--]                                        
                                        [#assign argValue="("+argument3.typeName +" *)"+argument3.name]
                                    [/#if]
                                    [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name}.${argument3.name} = ${argValue};                                    
                                    [/#if]
                               [#else] [#-- !argument.mandatory --]
                                    [#if argument3.status=="KO"]
                                        [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]//${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name}.${argument3.name} = ${argValue};
                                    [/#if]
                                    [#if argument3.status=="OK"]
                                    [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name}.${argument3.name} = ${argValue};
                                    [/#if]
                                [/#if][#-- if argument.mandatory --]
[/#list]
[/#if]
                            [/#list]
                            [/#if]
                        [/#list][#-- list  fargument.argument as argument--]
                        [/#if]
                    [#else][#-- if struct --] 
                    [#assign arg = ""]
                        [#if fargument.status=="OK" && fargument.value?? && fargument.value!="__NULL"]
                            [#if name??][#assign argIndex = inst?replace(name,"")]  [/#if]
                                            [#if argIndex??]
                                                [#assign argValue=fargument.value?replace("$Index",argIndex)]
                                                [#if fargument.returnValue!="true"]
                                                    [#assign arg = "" + adr + argValue]
                                                [/#if]
                                            [#else]
                                                [#if fargument.returnValue!="true"]
                                                    [#assign arg = "" + adr + fargument.value]                                                
                                                [/#if]
                                            [/#if]                       
                        [/#if]
                    [/#if]
                    [#if args == "" && arg!=""][#assign args = args + arg ][#else][#if arg!=""][#assign args = args + ', ' + arg][/#if][/#if]
                    [/#list]
                    [#assign retval=""]
            [#list method.arguments as argument]
            [#if argument.returnValue=="true"]
                [#assign retval=argument.name]
            [/#if]
            [/#list]

            [#--[#if retval??&& retval!=""]
            [#if nTab==2]#t#t[#else]#t[/#if]${retval} = ${method.name}(${args});--]
            [#-- else --]
                    [#-- Check on HAL_OK --]
                        [#if method.returnHAL=="false"]
            [#if nTab==2]#t#t[#else]#t[/#if]${method.name}(${args});
                        [#else]
                            [#-- [#if nTab==2]#t#t[#else]#t[/#if]${method.name}(${args});#n --]
                            [#if nTab==2]#t#t[#else]#t[/#if]if (${method.name}(${args}) != [#if method.returnHAL == "true"]HAL_OK[#else]${method.returnHAL}[/#if])
                            [#if nTab==2]#t#t[#else]#t[/#if]{
                            [#if nTab==2]#t#t[#else]#t[/#if]#tError_Handler();
                            [#if nTab==2]#t#t[#else]#t[/#if]}
                        [/#if]#n
            [#-- [/#if] --]
        [#else]
                    [#--[#if nTab==2]#t#t[#else]#t[/#if]${method.name}();#n --]
                        [#if method.returnHAL=="false"]
            [#if nTab==2]#t#t[#else]#t[/#if]${method.name}();
                        [#else]
                            [#-- [#if nTab==2]#t#t[#else]#t[/#if]${method.name}(${args});#n --]
                            [#if nTab==2]#t#t[#else]#t[/#if]if (${method.name}() != [#if method.returnHAL == "true"]HAL_OK[#else]${method.returnHAL}[/#if])
                            [#if nTab==2]#t#t[#else]#t[/#if]{
                            [#if nTab==2]#t#t[#else]#t[/#if]#tError_Handler();
                            [#if nTab==2]#t#t[#else]#t[/#if]}
                        [/#if]#n
                [/#if]			
        [/#if]
        [#if method.status=="KO"]
        #n [#if nTab==2]#t#t[#else]#t[/#if]//!!! ${method.name} is commented because some parameters are missing
            [#if method.arguments??]			
                [#list method.arguments as fargument]
                    [#if fargument.addressOf] [#assign adr = "&"][#else ] [#assign adr = ""][/#if]
                    [#if fargument.cast??] [#assign adr = fargument.cast + adr][/#if]
                    [#if fargument.genericType == "struct"][#assign arg = "" + adr + fargument.name]
                                        [#if fargument.context??]                   
                                            [#if fargument.context=="global"]
                                                [#if configModel.ipName=="DMA" || configModel.ipName=="BDMA" || config.ipName=="BDMA1"]
                                                [#assign instanceIndex = "_"+ configModel.dmaRequestName?lower_case]
                                                [#else]
                                                [#assign instanceIndex = inst?replace(name,"")]
                                                [#if configModel.ipName=="DFSDM" || configModel.ipName=="MDF" || configModel.ipName=="ADF"]
                                                    [#assign instanceIndex = ""]
                                                [/#if]
                                                [/#if]
                                            [/#if]
                                        [/#if]              
                        [#if instanceIndex??&&fargument.context=="global"][#assign arg = "" + adr + fargument.name + instanceIndex][#else][#assign arg = "" + adr + fargument.name][/#if]
                        [#if (!method.name?contains("Init")&&fargument.context=="global")]
                        [#else]
                        [#list fargument.argument as argument]	
                                [#if argument.genericType != "struct"]
                                [#if argument.mandatory && argument.value?? && argument.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global"][#assign argValue=argument.value?replace("$Index",instanceIndex)][#else][#assign argValue=argument.value][/#if]
                                    [#if nTab==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = ${argValue};
                                 [#else]
                                    [#if argument.name=="Instance"]
                                        [#if nTab==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = ${inst};
                                    [/#if]                                
                                [/#if]
                            [#else]
                            [#list argument.argument as argument1]
                                [#if argument1.mandatory && argument1.value?? && argument1.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global"][#assign argValue=argument1.value?replace("$Index",instanceIndex)][#else][#assign argValue=argument1.value][/#if]
                                [#if nTab==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument1.name} = ${argValue};
                                [/#if]
                            [/#list]
                            [/#if]
                            [/#list]
[/#if]
                                      [/#if][#-- if argument != struct --]
                    [#if args == ""][#assign args = args + arg ]
                    [#else][#assign args = args + ', ' + arg]
                                        [/#if]
                                [/#list]
                                [#if nTab==2]#t#t[#else]#t[/#if]#t//${method.name}(${args});
                        [#else] [#-- if method without argument --]
                               [#-- [#if nTab==2]#t#t[#else]#t[/#if]${method.name}()#n; --]
                            [#if method.returnHAL=="false"]
                                [#if nTab==2]#t#t[#else]#t[/#if]${method.name}();
                            [#else]
                                [#-- [#if nTab==2]#t#t[#else]#t[/#if]${method.name}(${args});#n --]
                                [#if nTab==2]#t#t[#else]#t[/#if]if (${method.name}() != [#if method.returnHAL == "true"]HAL_OK[#else]${method.returnHAL}[/#if])
                                [#if nTab==2]#t#t[#else]#t[/#if]{
                                [#if nTab==2]#t#t[#else]#t[/#if]#tError_Handler();
                                [#if nTab==2]#t#t[#else]#t[/#if]}
                            [/#if]#n
                        [/#if]
                [/#if]
        [/#list]
[/#if]
[#-- assign instanceIndex = "" --]
 [#-- else there is no LibMethod to call--]
[/#macro]
[#-- End macro generateConfigModelCode --]


[#-- macro getLocalVariable of a config Start--]
[#macro getLocalVariable configModel1 listOfLocalVariables resultList]
    [#if configModel1.methods??] 
        [#assign methodList1 = configModel1.methods]
    [#else] [#assign methodList1 = configModel1.libMethod]
    [/#if]
 [#assign myListOfLocalVariables = listOfLocalVariables]
    [#list methodList1 as method][#-- list methodList1 --][#if method.arguments?? && method.status!="WARNING"]
        [#list method.arguments as argument][#-- list method.arguments --]
            [#if argument.genericType == "struct"][#-- if struct --]
                [#if argument.context??][#-- if argument.context?? --]
                    [#if argument.context!="global"&&argument.status!="WARNING"&&argument.status!="NULL"] [#-- if !global --]
                    [#assign varName= " "+argument.name]                    
                    [#assign ll= myListOfLocalVariables?split(" ")]
                    [#assign exist=false]
                    [#list ll as var  ]
                        [#if var==argument.name]
                            [#assign exist=true]
                        [/#if]
                    [/#list]
                    [#if !exist]  [#-- if exist --]                  
                    #t${argument.typeName} ${argument.name} = {0};                        
                      [#assign myListOfLocalVariables = myListOfLocalVariables + " "+ argument.name]
                      [#assign resultList = myListOfLocalVariables]
                    [/#if][#-- if exist --]
                    [/#if][#-- if global --]
                [#else][#-- if context?? --]
                #t${argument.typeName} ${argument.name} = {0};
            [/#if][#-- if argument.context?? --]

            [#-- Array type --]
            [#list argument.argument as subArg] [#-- list subArg --]
                [#if (subArg.genericType=="Array" && sub) && (subArg.context!="global")] [#-- if genericType == "Array" --]
                    ${subArg.typeName} ${subArg.name}[${subArg.arraySize}] ; 
                [/#if] [#-- if genericType == "Array" --]
                [#if subArg.genericType =="struct"]
                    [#list subArg.argument as subArg1] [#-- list subArg1 --]
                        [#if subArg1.genericType=="Array" && (subArg1.context!="globalConst")  && subArg1.context!="globalInit"] [#-- if genericType == "Array" --]
                           [#if subArg1.value?? && subArg1.value!="__NULL"]
                                #t ${subArg1.typeName} ${subArg1.name}[${subArg1.arraySize}] ; 
                            [/#if]
                        [/#if] [#-- if genericType == "Array" --]
                    [/#list]
                [/#if]
            [/#list] [#-- list subArg --]
[#else][#-- if non struct --]
                [#if argument.context??][#-- if argument.context?? --]
                    [#if argument.context!="global"&&argument.status!="WARNING"&&argument.status!="NULL"&&argument.returnValue="true"] [#-- if !global --]
                    [#assign varName= " "+argument.name]                    
                    [#assign ll= myListOfLocalVariables?split(" ")]
                    [#assign exist=false]
                    [#list ll as var  ]
                        [#if var==argument.name]
                            [#assign exist=true]
                        [/#if]
                    [/#list]
                    [#if !exist]  [#-- if exist --]                  
                    #t${argument.typeName} ${argument.name} = {0};                        
                      [#assign myListOfLocalVariables = myListOfLocalVariables + " "+ argument.name]
                      [#assign resultList = myListOfLocalVariables]
                    [/#if][#-- if exist --]
                    [/#if][#-- if global --]
                [#else][#-- if context?? --]
                #t${argument.typeName} ${argument.name} = {0};
            [/#if]
            [/#if][#-- if struct --]
        [/#list][#-- list method.arguments --]
        [/#if]
    [/#list][#-- list methodList1 --]
[/#macro]
[#-- macro getLocalVariable of a config End--]

[#macro optinclude name]
  [#assign objectConstructor = "freemarker.template.utility.ObjectConstructor"?new()]
  [#assign file = objectConstructor("java.io.File",workspace+"/"+name)]
  [#assign exist = file.exists()]
  [#if exist]
    [#include "/"+name]
  [/#if]
[/#macro]

[#function fileExist name]    
  [#assign result = "false"]
  [#assign objectConstructor = "freemarker.template.utility.ObjectConstructor"?new()]
  [#assign file = objectConstructor("java.io.File",workspace+"/" + name)]
  [#assign exist = file.exists()]  
  [#if exist]  	
    [#return "true"]
  [#else]
  	[#return "false"]
  [/#if]
[/#function]

[#macro optincludeFile path name]
  [#assign objectConstructor = "freemarker.template.utility.ObjectConstructor"?new()]
  [#assign file = objectConstructor("java.io.File",workspace+"/"+path+"/"+name)]
  [#assign exist = file.exists()]
  [#if exist]
    #include "${name}"
  [/#if]
[/#macro]

[#macro generateConfigModelListCode configModel inst nTab index]
[#assign listofDeclaration = ""]
[#assign listofCalledMethod = ""]

[#list configModel.configs as config]
[#assign bz36245=false]
[#assign link = "."]
[#if config.methods??] [#-- if the pin configuration contains a list of LibMethods--]
    [#assign methodList = config.methods]
[#else] [#assign methodList = config.libMethod]

[/#if]
[#assign writeConfigComments=false]
[#list methodList as method]
    [#if method.status=="OK"][#assign writeConfigComments=true][/#if]
[/#list]
[#if writeConfigComments]
[#if config.ipName?contains("CORTEX")]
[#if config.comments?? && config.comments!=""]#t/** ${config.comments}#n#t*/[/#if]
[#else]
[#if config.comments?? && config.comments!="" && config.ipName?contains("PWR") && config.comments?contains("UCPD")]#t/** ${config.comments?replace("#t","#t")}#n#t*/
[#else]
[#if config.comments?? && config.comments!=""]#n#t/** ${config.comments?replace("#t","#t")}#n#t*/[/#if]
[/#if]
[/#if]
[/#if]
    [#list methodList as method][#assign args = ""]	 
            [#if method.hardCode??] [#-- Hard code --]              
                ${method.hardCode.text?replace("$IpInstance",inst)} 
            [#else]
                [#if method.type == "Template"] [#-- Template code --]  
                    [#list method.name?split("/") as n]
                        [#assign tplName = n]
                    [/#list]
                    [@optinclude name=mxTmpFolder+"/${tplName?replace('ftl','tmp')}" /] 
                [/#if]
            [/#if]
[#assign errorCode = "HAL_OK"]
            [#if (method.name)?starts_with("ADV_LPBAM")]
               [#assign errorCode = "LPBAM_OK"]
            [/#if]
            [#if method.status=="OK" && method.type != "Template" && method.type != "HardCode"]
                [#if method.arguments??]
                    [#list method.arguments as fargument][#compress]
[#assign link = "."]
[#if fargument.refMethod??] [#-- CallLibMethod for Argument value --]
    [#assign argumentValue=""]
    [@callLibMethod CLmethod=fargument.refMethod configModelRef=configModel instRef=inst nTabRef=nTab indexRef=index argumentValue=argumentValue/]
    [#assign arg = argumentValue]
    [#if args == "" && arg!=""][#assign args = args + arg ][#else][#if arg!=""][#assign args = args + ', ' + arg][/#if][/#if]
[/#if] [#-- end if fargument.refMethod??--] [#-- New --]
                    [#if fargument.addressOf][#assign adr = "&"][#else ][#if method.name="HAL_DMAEx_List_Init"][#assign link = "->"][/#if][#assign adr = ""][/#if]
                    [#if fargument.cast??] [#assign adr = fargument.cast + adr][/#if][/#compress] 
                    [#if fargument.genericType == "struct" && fargument.argumentReference == "RefParameter"]
                        [#if fargument.optional == "output"]
                                [#assign arg = "" + adr + fargument.name]
                                [#if fargument.cast??][#assign arg = fargument.cast + arg][/#if]
                        [/#if]
                        [#if fargument.context?? && fargument.optional!="output"]
                            [#if fargument.context=="global"]                            
                                [#if config.ipName=="DMA" || config.ipName=="BDMA"]
                                    [#assign instanceIndex = "_"+ config.dmaRequestName?lower_case]
                                [#else]
                                    [#if config.ipName?starts_with("GPDMA") || config.ipName?starts_with("LPDMA")]
                                        [#assign instanceIndex = ""]
                                   [#else]
                                        [#-- [#assign instanceIndex = instRef?replace(name,"")]--]
                                        [#if index??][#assign instanceIndex = index][#else][#if name??][#assign instanceIndex = inst?replace(name,"")][/#if][/#if]
                                                     [#if configModel.ipName=="DFSDM" || configModel.ipName=="MDF" || configModel.ipName=="ADF"]
                                                         [#assign instanceIndex = ""]
                                                     [/#if]
                                        [/#if]
                                    [/#if]
                            [/#if]
                        [/#if]
                        [#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"][#if fargument.status!="NULL"][#assign arg = "" + adr + fargument.name + instanceIndex][#else][#assign arg = "NULL"][/#if][#else][#if  fargument.status!="NULL"][#assign arg = "" + adr + fargument.name][#else][#assign arg = "NULL"][/#if][/#if]
                        [#-- [#assign arg = "" + adr + fargument.name] --]
                        [#if ((!method.name?contains("Init")&&fargument.context=="global")||(fargument.optional=="output"))]
                        [#-- MDF : if ((!(fargument.context=="global"))||(fargument.optional=="output"))--]
                        [#else]
                            [#assign index1 =1] [#-- index of argument struct level1 --]
                        [#list fargument.argument as argument]	

                            [#if argument.genericType != "struct"]
                                [#if argument.mandatory && !argument.refMethod??] 
                                [#if argument.value?? && argument.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]
                                        [#assign argValue=argument.value?replace("$Index",instanceIndex)]
                                    [#else]
                                        [#assign argValue=argument.value]
                                    [/#if][#-- if global --]
                                    [#-- Bz40086 - Begin tweak of the value in case of ADC --]
[#if ((config.name == "ADC_RegularChannelConfig" && (FamilyName!="STM32C0" || FamilyName!="STM32G0" || FamilyName!="STM32WL"|| FamilyName!="STM32U5") ) || config.name == "ADC_InjectedChannelConfig" ||  ((FamilyName=="STM32C0" || FamilyName=="STM32G0" || FamilyName=="STM32WL" || FamilyName=="STM32U5") && config.name == "ADC_RegularChannelRankConfig")) && (FamilyName!="STM32F0" && FamilyName!="STM32L0" && FamilyName!="STM32F2" && FamilyName!="STM32F4")]                                        [#list argument?keys as k]
                                            [#if k == "name" && !(argument.value)?starts_with("ADC")]
                                                [#if argument[k] == "Rank"]
                                                 
                                                    [#assign argValue="ADC_REGULAR_RANK_"+argument.value]
                                                [#elseif argument[k] == "InjectedRank"]
                                                    [#assign argValue="ADC_INJECTED_RANK_"+argument.value]
                                                [/#if]
                                            [/#if]
                                        [/#list]
                                    [/#if]                                   
                                    [#-- Bz40086 End tweak of the value in case of ADC --]
                                    [#if argument.genericType=="Array" && argument.context!="globalConst" && argument.context!="globalInit"][#-- if genericType=Array --]
                                    [#assign valList = argument.value?split(argument.arraySeparator)]     
                                            [#assign i = 0]                                  
                                        [#list valList as val]
                                            [#if argument.base == "10"]
                                                #t${argument.name}[${i}] = ${val};
                                            [#else]
                                                #t${argument.name}[${i}] = 0x${val};
                                            [/#if]
                                            [#assign i = i+1]
                                        [/#list]
                                        [#assign argValue="&"+argument.name]                                    
                                    [/#if] [#-- if genericType=Array --]
                                    [#if argument.genericType=="Array" && (argument.context=="globalConst" || argument.context=="globalInit")][#-- if genericType=Array and gloabl--]                                        
                                        [#assign argValue="("+argument.typeName +" *)"+argument.name]
                                    [/#if]
                                    [#if argument.value!="" && argument.value!="N/A"]
                                    [#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"][#assign varName=fargument.name + link +instanceIndex][#else][#assign varName=fargument.name][/#if]
                                        [#assign indicator = varName+link+argument.name+" = "+argValue+" "]
                                        [#assign indicatorName = varName+link+argument.name]
                                        [#if !listofDeclaration?contains(indicator)][#-- if not repeted --]
                                            [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"][#assign varName=fargument.name +link +instanceIndex]${fargument.name}${instanceIndex}[#else][#assign varName=fargument.name]${fargument.name}[/#if]${link}${argument.name} = ${argValue};
                                            [#assign listofDeclaration = listofDeclaration?replace(indicatorName+" =","")]
                                            [#assign listofDeclaration = listofDeclaration +", "+ varName+link+argument.name+" = "+argValue+" "]                                                                                 
                                        [/#if]
                                    [#else]
                                    [#if nTab==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name} = [#if argument.value!="N/A"]${argValue}[/#if];
                                    [/#if]                                                                     
                                    [/#if]
                                    [#else] [#-- else argument.mandatory--]
                                      [#if fargument.name!="GPIO_InitStruct" && fargument.name!="GPIO_Init"]
                                            [#if argument.name=="Instance"][#-- if argument=Instance--]
                                              [#-- calculate the value of Instance argument if contains $Index --]
                                                [#if  (argument.value??&& argument.value!="__NULL") && (argument.value?contains("$Index"))]
                                                    [#assign instanceValue=argument.value?replace("$Index",index)]
[#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name +instanceIndex][#else][#assign varName=fargument.name][/#if]
                                                    [#assign indicator = varName+link+argument.name+" = "+instanceValue+" "]
                                                    [#if !listofDeclaration?contains(indicator)]    [#-- if not repeted --]
                                                    [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name} = ${instanceValue};
                                                            [#assign listofDeclaration = listofDeclaration +", "+ indicator]
                                                    
                                                    [/#if]
                                                [#else]
[#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name+instanceIndex][#else][#assign varName=fargument.name][/#if] [#if argument.value?? && argument.value!="__NULL"][#assign argv =argument.value][#else][#assign argv=inst][/#if]
                                                   [#assign indicator = varName+link+argument.name+" = "+argv+" "]
                                                   [#if !listofDeclaration?contains(indicator)] [#-- if not repeted --]
                                                    [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name} = [#if argument.value?? && argument.value!="__NULL"]${argument.value};[#else]${inst};[/#if]
                                                            [#assign listofDeclaration = listofDeclaration +", "+ indicator]

                                                            [#if index1 == fargument.argument?size]
                                                                #n
                                                            [/#if]
                                                            [#if configModel.ipName=="RTC" && config.name=="RTC_Init_Only"]
                                                                [#list configModel.configs as bz36245config]
                                                                    [#if bz36245config.name=="RTC_Init"]
                                                                        [#assign bz36245=true]
                                                                    [/#if]
                                                                [/#list]
                                                            [/#if]
                                                            [#if bz36245]
                                                              
                                                            [/#if]
                                                   [/#if]
                                                [/#if]
                                          [#else]
                                              [#if argument.status=="KO"]
                                                   [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"]//${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name} = ${argument.value};                                        
                                              [/#if]
                                              [#if argument.value?? && argument.value!="__NULL"]

[#if argument.refMethod??] [#-- CallLibMethod for Argument value --]
    [#assign argumentValue=""]
    [@callLibMethod CLmethod=argument.refMethod configModelRef=configModel instRef=inst nTabRef=nTab indexRef=index argumentValue=argumentValue/]
    [#assign argTmp = argumentValue]
[/#if] [#-- end if fargument.refMethod??--] [#-- New --]
                [#if argument.value!="N/A"]
                                                        [#if argument.refMethod??][#assign argValue=argumentValue][#else][#assign argValue=argument.value][/#if]
                                                        [#if instanceIndex??&&fargument.context=="global"][#assign varName=fargument.name+instanceIndex][#else][#assign varName=fargument.name][/#if]
                                                        [#assign indicator = varName+link+argument.name+" = "+argValue+" "]
                                                        [#assign indicatorName = varName+link+argument.name]
                                                        [#if !listofDeclaration?contains(indicator)][#-- if not repeted --] 
                                                            [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name +link +instanceIndex]${fargument.name}${instanceIndex}[#else][#assign varName=fargument.name]${fargument.name}[/#if].${argument.name} = ${argValue};
                                                            [#assign listofDeclaration = listofDeclaration?replace(indicatorName+" =","")]
                                                            [#assign listofDeclaration = listofDeclaration +", "+ varName+link+argument.name+" = "+argValue+" "]                                                                                 
                                                        [/#if]
                                                    [/#if]
[#if index1 == fargument.argument?size]
                                                                #n
                                                            [/#if]

                                              [/#if]                                    
                                          [/#if][#-- if argument=Instance--]                                
                                      [/#if]    
                                [/#if][#-- if argument.mandatory--]     
                            [#else]
                            [#assign index2=0]


[#list argument.argument as argument2]
			[#if argument2.genericType!="struct"]
[#if config.ipName=="ETH"]
                                [#if argument2.value??][#assign argValue=argument2.value][#else] [#assign argValue=""][/#if]
                                [#if argument2.mandatory]
                                    [#if argument2.value??]
                                    [#if instanceIndex??&&fargument.context=="global"][#assign argValue=argument2.value?replace("$Index",instanceIndex)][#else][#assign argValue=argument2.value][/#if]
                                    [#if argument2.genericType=="Array"][#-- if genericType=Array --] 
                                        [#assign valList = argument2.value?split(":")]     
                                            [#assign i = 0]                                  
                                        [#list valList as val] 
                                            [#if argument2.typeName == "10"]
                                                #t${argument2.name}[${i}] = ${val};
                                            [#else]
                                                #t${argument2.name}[${i}] = 0x${val};
                                            [/#if]                                            [#assign i = i+1]
                                        [/#list]
                                        [#assign argValue="&"+argument2.name+"[0]"]
                                    [/#if] [#-- if genericType=Array --]
                                    [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name}.${argument2.name} = ${argValue};                                    
                                    [/#if]
                               [#else] [#-- !argument.mandatory --]
                                    [#if argument2.status=="KO"]
                                        [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]//${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name} = ${argValue};
                                    [/#if]
                                    [#if argument2.status=="OK"]
                                    [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name}.${argument2.name} = ${argValue};
                                    [/#if]
[/#if]
                                [/#if][#-- if argument.mandatory --]
				


[#if config.ipName!="ETH"]
                                [#if argument2.value?? && argument2.value!="__NULL"][#assign argValue=argument2.value][#else] [#assign argValue=""][/#if]
                                [#if argument2.mandatory]
                                    [#if argument2.value?? && argument2.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign argValue=argument2.value?replace("$Index",instanceIndex)][#else][#assign argValue=argument2.value][/#if]
                                    [#if argument2.genericType=="Array" && argument2.context!="globalConst" && argument2.context!="globalInit"][#-- if genericType=Array --]
                                        [#if argument2.arraySeparator?? && argument2.arraySeparator!=""]
                                        [#assign valList = argument2.value?split(argument2.arraySeparator)]     
                                        [#else]
                                            [#assign valList = argument2.value?split(":")]
                                        [/#if]
                                            [#assign i = 0]
                                            [#assign argValue="&"+argument2.name+"[0]"]
                                            [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name +instanceIndex][#else][#assign varName=fargument.name][/#if]

                                        [#list valList as val]
                                            [#if nTab==2]#t#t[#else]#t[/#if][#t]
                                            [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#t]
                                                ${fargument.name}${instanceIndex}[#t]
                                            [#else]
                                                ${fargument.name}[#t]
                                            [/#if]
                                            .${argument.name}.${argument2.name}[${i}] =[#t]
                                            [#if argument2.base == "10"]
                                                #t${val};
                                            [#else]
                                                #t0x${val};
                                            [/#if]
                                          [#assign i = i+1]
                                        [/#list]
                                            [#if index2 == argument.argument?size]
                                                 [#-- add space line at the end of argument setting --]
                                            [/#if]
                                    [#else] [#-- if genericType=Array --]
                                    [#-- if argument is a global array --]
                                    [#if argument2.genericType=="Array" && (argument2.context=="globalConst" || argument2.context=="globalInit")][#-- if genericType=Array and gloabl--]                                        
                                        [#assign argValue="("+argument2.typeName +" *)"+argument2.variableName]
                                    [/#if]                                         
                                    [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name +instanceIndex][#else][#assign varName=fargument.name][/#if]
                                                    [#assign indicatorName = varName+link+argument.name+"."+argument2.name]
                                                    [#assign indicator = varName+link+argument.name+"."+argument2.name+" = "+argValue+" "]
                                                    [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]
                                                        [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name}.${argument2.name} = ${argValue};                                    

                                                        [#if index2 == argument.argument?size]
                                                            #n [#-- add space line at the end of argument setting --] 
                                                        [/#if]
                                                            [#assign listofDeclaration = listofDeclaration?replace(indicatorName+" =","")]
                                                            [#assign listofDeclaration = listofDeclaration +", "+ indicator]
                                                    [/#if]
                                        [/#if]
                                    [/#if]
                               [#else] [#-- !argument.mandatory --]
                                    [#if argument2.status=="WARNING"]
                                        [#if argument2.name=="ShieldIOs"]
                                            [#assign argValue ="0"]
                                            [#assign indicatorName = varName+link+argument.name+"."+argument2.name]
                                            [#assign indicator = varName+link+argument.name+"."+argument2.name+" = "+argValue+" "]
                                            [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]
                                                [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name}.${argument2.name} = ${argValue};                                    
                                               [#if index2 == argument.argument?size]
                                                        #n [#-- add space line at the end of argument setting --]
                                                [/#if]
                                            [/#if]
                                        [/#if]
                                    [/#if]
                                    [#if argument2.status=="KO"]
                                        [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"]//${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name}.${argument2.name} = ${argValue};
                                    [/#if]
                                    [#if argument2.status=="OK"]
[#if instanceIndex??&&fargument.context=="global"][#assign varName=fargument.name +instanceIndex][#else][#assign varName=fargument.name][/#if]
                                         [#assign indicatorName = varName+link+argument.name+"."+argument2.name]
                                         [#assign indicator = varName+link+argument.name+"."+argument2.name+" = "+argValue+" "]
                                         [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]   
                                            [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name}.${argument2.name} = ${argValue};
                                            [#assign listofDeclaration = listofDeclaration?replace(indicatorName+" =","")]
                                            [#assign listofDeclaration = listofDeclaration +", "+ indicator]                                            
                                         [/#if]
                                    [/#if]

[/#if]
                                [/#if][#-- if argument.mandatory --]
[#else]
[#list argument2.argument as argument3]
    [#if argument3.genericType!="struct"]
        [#if argument3.value?? && argument3.value!="__NULL"][#assign argValue=argument3.value][#else] [#assign argValue=""][/#if]
                                [#if argument3.mandatory]
                                    [#if argument3.value?? && argument3.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign argValue=argument3.value?replace("$Index",instanceIndex)][#else][#assign argValue=argument3.value][/#if]
                                    [#if argument3.genericType=="Array" && argument3.context!="globalConst" && argument3.context!="globalInit"][#-- if genericType=Array --] 
                                        [#if argument3.arraySeparator?? && argument3.arraySeparator!=""]
                                            [#assign valList = argument3.value?split(argument3.arraySeparator)]     
                                        [#else]
                                            [#assign valList = argument3.value?split(":")]
                                        [/#if]
                                            [#assign i = 0]                                  
                                        [#list valList as val] 
                                            [#if argument3.base == "10"]
                                                #t${argument3.name}[${i}] = ${val};
                                            [#else]
                                                #t${argument3.name}[${i}] = 0x${val};
                                            [/#if]
                                            [#assign i = i+1]
                                        [/#list]
                                        [#assign argValue="&"+argument3.name+"[0]"]
                                    [/#if] [#-- if genericType=Array --]
                                     [#-- if argument is a global array --]
                                    [#if argument3.genericType=="Array" && (argument3.context=="globalConst"||argument3.context=="globalInit")][#-- if genericType=Array and gloabl--]                                        
                                        [#assign argValue="("+argument3.typeName +" *)"+argument3.name]
                                    [/#if]
[#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name +instanceIndex][#else][#assign varName=fargument.name][/#if]
                                         [#assign indicatorName = varName+link+argument.name+"."+argument2.name+"."+argument3.name]
                                         [#assign indicator = varName+link+argument.name+"."+argument2.name+"."+argument3.name+" = "+argValue+ " "]
                                         [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]                                      
                                            [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name}.${argument2.name}.${argument3.name} = ${argValue};                                    
                                            [#assign listofDeclaration = listofDeclaration?replace(indicatorName+" =","")]
                                            [#assign listofDeclaration = listofDeclaration +", "+ indicator]
                                         [/#if]                                       [/#if]
                               [#else] [#-- !argument.mandatory --]
                                    [#if argument3.status=="KO"]
[#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name +instanceIndex][#else][#assign varName=fargument.name][/#if]
                                         [#assign indicatorName = varName+link+argument.name+"."+argument2.name+"."+argument3.name]
                                         [#assign indicator = varName+link+argument.name+"."+argument2.name+"."+argument3.name+" = "+argValue+" "] 
                                         [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]  
                                            [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name}.${argument2.name}.${argument3.name} = ${argValue};
                                            [#assign listofDeclaration = listofDeclaration?replace(indicatorName+" =","")]
                                            [#assign listofDeclaration = listofDeclaration +", "+ indicator]
                                         [/#if]
                                    [/#if]
                                    [#if argument3.status=="OK"]
[#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name +instanceIndex][#else][#assign varName=fargument.name][/#if]
                                         [#assign indicatorName = varName+link+argument.name+"."+argument2.name+"."+argument3.name]
                                         [#assign indicator = varName+link+argument.name+"."+argument2.name+"."+argument3.name+" = "+argValue+" "] 
                                         [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]  
                                            [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name}.${argument2.name}.${argument3.name} = ${argValue};
                                            [#assign listofDeclaration = listofDeclaration?replace(indicatorName+" =","")]
                                            [#assign listofDeclaration = listofDeclaration +", "+ indicator]
                                        [/#if]
                                    [/#if]
                                [/#if][#-- if argument.mandatory --]
    [#else]
		[#list argument3.argument as argument4]
			[#if argument4.genericType!="struct"]
				[#if argument4.value?? && argument4.value!="__NULL"][#assign argValue=argument4.value][#else] [#assign argValue=""][/#if]
				[#if argument4.value?? && argument4.value!="__NULL"]
					[#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name +instanceIndex][#else][#assign varName=fargument.name][/#if]
                    [#assign indicatorName = varName+link+argument.name+"."+argument2.name+"."+argument3.name+"."+argument4.name]
                    [#assign indicator = varName+link+argument.name+"."+argument2.name+"."+argument3.name+"."+argument4.name+" = "+argValue+" "] 
                    [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]  
                        [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name}.${argument2.name}.${argument3.name}.${argument4.name} = ${argValue};                                    
                        [#assign listofDeclaration = listofDeclaration?replace(indicatorName+" =","")]
                        [#assign listofDeclaration = listofDeclaration +", "+ indicator]
                    [/#if]
				[/#if]
			[#else]
				[#list argument4.argument as argument5]
					[#if argument5.genericType!="struct"]
						[#if argument5.value?? && argument5.value!="__NULL"][#assign argValue=argument5.value][#else] [#assign argValue=""][/#if]
						[#if argument5.value?? && argument5.value!="__NULL"]
                            [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name +instanceIndex][#else][#assign varName=fargument.name][/#if]
                            [#assign indicatorName = varName+link+argument.name+"."+argument2.name+"."+argument3.name+"."+argument4.name+"."+argument5.name]
                            [#assign indicator = varName+link+argument.name+"."+argument2.name+"."+argument3.name+"."+argument4.name+"."+argument5.name+" = "+argValue+" "] 
                            [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]  
                                [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name}.${argument2.name}.${argument3.name}.${argument4.name}.${argument5.name} = ${argValue};                                    
                                [#assign listofDeclaration = listofDeclaration?replace(indicatorName+" =","")]
                                [#assign listofDeclaration = listofDeclaration +", "+ indicator]
                            [/#if]
						[/#if]
					[/#if]
				[/#list]
			[/#if]
		 [/#list]
    [/#if]                                
[/#list]
[/#if]

[#assign index2=index2 + 1]
                            [/#list]
                            [/#if]
[#assign index1 =index1 + 1]


                        [/#list][#-- list  fargument.argument as argument--]
                        [/#if]
                    [#else][#-- if fargument a simple type struct --]
                        [#if fargument.genericType=="Array"][#-- if genericType=Array --]
                            [#if fargument.context!="globalConst" && fargument.context!="globalInit"]
                                [#assign valList = fargument.value?split(fargument.arraySeparator)]
                                [#assign i = 0]
                                [#list valList as val]
                                    [#if fargument.base == "10"]
                                        #t${fargument.name}[${i}] = ${val};
                                    [#else]
                                        #t${fargument.name}[${i}] = 0x${val};
                                    [/#if]
                                    [#assign i = i+1]
                                [/#list]
                            [/#if]
                            [#if fargument.status!="NULL"]
                                [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"]
                                    [#assign arg = "" + adr + fargument.name + instanceIndex]
                                [#else]
                                    [#assign arg = "" + adr + fargument.name]
                                [/#if]
                            [#else]
                                [#assign arg = "NULL"]
                            [/#if]
                        [#else] [#-- if genericType=Array --]
                    [#assign arg = ""]
                        [#if fargument.status=="OK" && fargument.value?? && fargument.value!="__NULL" && fargument.argumentReference == "RefParameter"]
                            [#if name??][#assign argIndex = inst?replace(name,"")]  [/#if]
                                            [#if argIndex??] 
                                                [#assign argValue=fargument.value?replace("$Index",argIndex)]
                                                [#if fargument.returnValue!="true"]
                                                    [#assign arg = "" + adr + argValue]
                                                [/#if]
                                            [#else]
                                                [#if fargument.returnValue!="true"]
                                                    [#assign arg = "" + adr + fargument.value]                                                
                                                [/#if]
                                            [/#if]    
                        [#else] 
                            [#if fargument.status=="NULL"][#assign arg = "" + adr + "NULL"] [/#if]      
                    [/#if]
                        [/#if] [#-- if genericType=Array --]
                    [/#if] [#-- end if fargument is struct --]
                    [#if args == "" && arg!=""][#assign args = args + arg ][#else][#if arg!=""][#assign args = args + ', ' + arg][/#if][/#if]
                    [/#list]
                    [#assign retval=""]
            [#list method.arguments as argument]
            [#if argument.returnValue=="true"]
                [#assign retval=argument.name]
            [/#if]
            [/#list]
[#if !(method.callMethod) || (S_FATFS_SDIO?? && (inst=="SDIO" || inst?starts_with("SDMMC")) && !(method.name=="HAL_RCCEx_PeriphCLKConfig"))] [#-- if HAL_SD_Init  and SDIO is used with FATFS--]
[#else]		    
                [#if inst?contains("ETH")]
                    #n
                    #t/* USER CODE BEGIN MACADDRESS */
                    #t#t
                    #t/* USER CODE END MACADDRESS */
                    #n
                [/#if]

[#--[#if nTab==2]#t#t[#else]#t[/#if]${method.name}(${args});#n--]
        [#if method.returnHAL=="false"]
            [#-- Check if Method is already called (listofCalledMethod)--]
            [#assign methodName = method.name + "("+args+")"]
            [#if !listofCalledMethod?contains(methodName)]
                [#if nTab==2]#t#t[#else]#t[/#if]${method.name}(${args});
                [#if method.optimizale??&&method.optimizale==true]
                [#assign listofCalledMethod = listofCalledMethod + ", "+ methodName]
                [/#if]
            [#if bz36245]

             }

               [/#if]
            [/#if]
        [#else]
            [#-- [#if nTab==2]#t#t[#else]#t[/#if]${method.name}(${args});#n --]
            [#-- Check if Method is already called (listofCalledMethod)--]
            [#assign methodName = method.name + "("+args+")"] 
            [#if !listofCalledMethod?contains(methodName) && method.optimizale??]
                [#if nTab==2]#t#t[#else]#t[/#if]if (${method.name}(${args}) != [#if method.returnHAL == "true"]${errorCode}[#else]${method.returnHAL}[/#if])
                [#if nTab==2]#t#t[#else]#t[/#if]{
                [#if nTab==2]#t#t[#else]#t[/#if]#tError_Handler();

				

                [#if nTab==2]#t#t[#else]#t[/#if]}
                [#if method.optimizale??&&method.optimizale==true]
                [#assign listofCalledMethod = listofCalledMethod + ", "+ methodName]
                [/#if]


            [/#if]
        [/#if]
[/#if]
                    
            [#else]
                    [#if !(method.callMethod) || (S_FATFS_SDIO?? && (inst=="SDIO" || inst?starts_with("SDMMC")))] [#-- if HAL_SD_Init  and SDIO is used with FATFS--][#else]
                        [#--[#if nTab==2]#t#t[#else]#t[/#if]${method.name}();#n--]
                        [#if method.returnHAL=="false"]
            [#if nTab==2]#t#t[#else]#t[/#if]${method.name}();
                        [#else]
                            [#-- [#if nTab==2]#t#t[#else]#t[/#if]${method.name}(${args});#n --]
                            [#if nTab==2]#t#t[#else]#t[/#if]if (${method.name}() != [#if method.returnHAL == "true"]${errorCode}[#else]${method.returnHAL}[/#if])
                            [#if nTab==2]#t#t[#else]#t[/#if]{
                            [#if nTab==2]#t#t[#else]#t[/#if]#tError_Handler();
                            [#if nTab==2]#t#t[#else]#t[/#if]}
                        [/#if]#n                  
                    [/#if]
                [/#if]			
        [/#if]
        [#if method.status=="KO"]
        #n [#if nTab==2]#t#t[#else]#t[/#if]//!!! ${method.name} is commented because some parameters are missing
            [#if method.arguments??]			
                [#list method.arguments as fargument]
                    [#if fargument.addressOf] [#assign adr = "&"][#else ] [#assign adr = ""][/#if]
                    [#if fargument.cast??] [#assign adr = fargument.cast + adr][/#if]
                    [#if fargument.genericType == "struct"][#assign arg = "" + adr + fargument.name]
                                        [#if fargument.context??]                   
                                            [#if fargument.context=="global"]
                                                [#if config.ipName=="DMA" || config.ipName=="BDMA" || config.ipName=="BDMA1"]
                                                [#assign instanceIndex = "_"+ config.dmaRequestName?lower_case]
                                                [#else]
                                               [#if name??] [#assign instanceIndex = inst?replace(name,"")][/#if]
                                                [#if configModel.ipName=="DFSDM" || configModel.ipName=="MDF" || configModel.ipName=="ADF"]
                                                    [#assign instanceIndex = ""]
                                                [/#if]                
                                                [/#if]
                                            [/#if]
                                        [/#if]              
                        [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign arg = "" + adr + fargument.name + instanceIndex][#else][#assign arg = "" + adr + fargument.name][/#if]
                        [#if (!method.name?contains("Init")&&fargument.context=="global")]
        [#-- MDF  --]
                        [#else]
                        [#list fargument.argument as argument]	
                                [#if argument.genericType != "struct"]
                                [#if argument.mandatory && argument.value?? && argument.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign argValue=argument.value?replace("$Index",instanceIndex)][#else][#assign argValue=argument.value][/#if]
                                    [#if nTab==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name} = ${argValue};
                                 [#else]
                                    [#if argument.name=="Instance"]
                                        [#if nTab==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name} = ${inst};
                                    [/#if]                                
                                [/#if]
                            [#else]
                            [#list argument.argument as argument1]
                                [#if argument1.mandatory && argument1.value?? && argument1.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign argValue=argument1.value?replace("$Index",instanceIndex)][#else][#assign argValue=argument1.value][/#if]
                                [#if nTab==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name}.${argument1.name} = ${argValue};
                                [/#if]
                            [/#list]
                            [/#if]
                            [/#list]
[/#if]
                                        [#else] [#-- if argument != struct --]
 [#if name??][#assign argIndex = inst?replace(name,"")]  
                                            [#assign argIndex = inst?replace(name,"")] 
[/#if]
                                            [#if argIndex??]
                                                [#assign argValue=fargument.value?replace("$Index",argIndex)]
                                                [#assign arg = "" + adr + argValue]
                                            [#else]
                                                [#assign arg = "" + adr + fargument.value]                                                
                                            [/#if]
                                        [/#if]
                    [#if args == ""][#assign args = args + arg ]
                    [#else][#assign args = args + ', ' + arg]
                                        [/#if]
                                [/#list]
                                [#if nTab==2]#t#t[#else]#t[/#if]#t//${method.name}(${args});
                        [#else] [#-- if method without argument --]
                            [#if method.returnHAL=="false"]
                            [#if nTab==2]#t#t[#else]#t[/#if]${method.name}();
                            [#else]
                                [#-- [#if nTab==2]#t#t[#else]#t[/#if]${method.name}(${args});#n --]
                                [#if nTab==2]#t#t[#else]#t[/#if]if (${method.name}() != [#if method.returnHAL == "true"]${errorCode}[#else]${method.returnHAL}[/#if])
                                [#if nTab==2]#t#t[#else]#t[/#if]{
                                [#if nTab==2]#t#t[#else]#t[/#if]#tError_Handler();
                                [#if nTab==2]#t#t[#else]#t[/#if]}
                            [/#if]#n
                               [#--[#if nTab==2]#t#t[#else]#t[/#if]${method.name}();--]
#n
                        [/#if]
                [/#if]
        [/#list]
[#-- assign instanceIndex = "" --]
 [#-- else there is no LibMethod to call--]
[#if bz36245]                                                           
    #n
    #t/* USER CODE BEGIN Check_RTC_BKUP */
    #t#t
    #t/* USER CODE END Check_RTC_BKUP */
    #n
[/#if]
[/#list]



[/#macro]
[#-- End macro generateConfigModelListCode --]


[#-- macro getLocalVariableList of a config Start--]
[#macro getLocalVariableList instanceData]
[#assign myListOfLocalVariables =""]
[#list instanceData.configs as configModel1]
    [#if configModel1.methods??] 
        [#assign methodList1 = configModel1.methods]
    [#else] [#assign methodList1 = configModel1.libMethod]
    [/#if]
    [#list methodList1 as method][#-- list methodList1 --][#if method.arguments?? && method.status!="WARNING"]
        [#list method.arguments as argument][#-- list method.arguments --]
            [#if argument.genericType == "struct"][#-- if struct --]
                [#assign ll= myListOfLocalVariables?split(" ")]
                [#assign exist=false]
                [#list ll as var  ]
                    [#if var==argument.name]
                        [#assign exist=true]
                    [/#if]
                [/#list]
                [#if argument.context??][#-- if argument.context?? --]
                    [#if argument.context!="global"&&argument.status!="WARNING"&&argument.status!="NULL"] [#-- if !global --]
                    [#assign varName= " "+argument.name]                    
                    
                    [#if !exist]  [#-- if exist --]                  
                    #t${argument.typeName} ${argument.name} = {0};                        
                      [#assign myListOfLocalVariables = myListOfLocalVariables + " "+ argument.name]
                      [#assign resultList = myListOfLocalVariables]
                    [/#if][#-- if exist --]
                    [/#if][#-- if global --]
                [#else][#-- if context?? --]
                    [#if !exist]  [#-- if exist --]                  
                    #t${argument.typeName} ${argument.name} = {0};                        
                      [#assign myListOfLocalVariables = myListOfLocalVariables + " "+ argument.name]
                      [#assign resultList = myListOfLocalVariables]
                    [/#if][#-- if exist --]               
            [/#if][#-- if argument.context?? --]
[#if configModel1.ipName!="ETH"]
            [#-- Array type --]
            [#list argument.argument as subArg] [#-- list subArg --]
                [#if subArg.genericType=="Array" && subArg.context!="globalConst" && sunArg.context!="globalInit"] [#-- if genericType == "Array" --] 
                    ${subArg.typeName} ${subArg.name}[${subArg.arraySize}] ; 
                [/#if] [#-- if genericType == "Array" --]
                [#if subArg.genericType =="struct"]
                    [#-- array inside struct is not considered as an array but as values
                    [#list subArg.argument as subArg1] [#-- list subArg1 -]
                        [#if subArg1.genericType=="Array" && subArg1.context!="globalConst" && subArg.context!="globalInit"] [#-- if genericType == "Array" -]
                            [#if subArg1.value?? && subArg1.value!="__NULL"]
                                #t ${subArg1.typeName} ${subArg1.name}[${subArg1.arraySize}] ;
                            [/#if]
                        [/#if] [#-- if genericType == "Array" -]
                    [/#list]
                    --]
                [/#if]
            [/#list] [#-- list subArg --]
[/#if]

[#if configModel1.ipName=="ETH"]
	   [#-- Array type --]
                       [#list argument.argument as subArg] [#-- list subArg --]
                [#if subArg.genericType=="Array"] [#-- if genericType == "Array" --]
                    ${subArg.typeName} ${subArg.name}[${subArg.arraySize}] ; 
                [/#if] [#-- if genericType == "Array" --]
                [#if subArg.genericType =="struct"]
                    [#list subArg.argument as subArg1] [#-- list subArg1 --]
                        [#if subArg1.genericType=="Array"] [#-- if genericType == "Array" --]
                           #t static ${subArg1.typeName} ${subArg1.name}[${subArg1.arraySize}]; 
                        [/#if] [#-- if genericType == "Array" --]
                    [/#list]
                [/#if]
            [/#list] [#-- list subArg --]
		[/#if]
           [#else][#-- if non struct --]
                [#if argument.genericType=="Array"] [#-- if genericType == "Array" --]
                    #t${argument.typeName} ${argument.name}[${argument.arraySize}] ;
                [#else]
                [#if argument.context??][#-- if argument.context?? --]

                [#else][#-- if context?? --]
                #t${argument.typeName} ${argument.name} = {0};
            [/#if]
                [/#if][#-- if genericType == "Array" --]
            [/#if][#-- if struct --]
        [/#list][#-- list method.arguments --]
        [/#if]
    [/#list][#-- list methodList1 --]
[/#list]
[/#macro]
[#-- macro getLocalVariableList of a config End--]

[#-- macro generate USB wake-up interrupt code --]
[#macro generateUsbWakeUpInterrupt ipName tabN]
    [#if ipName?contains("_FS")]
        [#if FamilyName=="STM32L4"]
            [#if tabN==2]#t#t[#else]#t#t#t[/#if]/* Enable EXTI Line 17 for USB wakeup */
        [#else]
            [#if tabN==2]#t#t[#else]#t#t#t[/#if]/* Enable EXTI Line 18 for USB wakeup */
        [/#if]
    [#else]
        [#if FamilyName=="STM32L0" || FamilyName=="STM32F0"|| FamilyName=="STM32G4"]
            [#if tabN==2]#t#t[#else]#t#t#t[/#if]/* Enable EXTI Line 18 for USB wakeup */
        [#elseif FamilyName=="STM32WB"]
            [#if tabN==2]#t#t[#else]#t#t#t[/#if]/* Enable EXTI Line 28 for USB wakeup */
        [#else]
            [#if tabN==2]#t#t[#else]#t#t#t[/#if]/* Enable EXTI Line 20 for USB wakeup */
        [/#if]
    [/#if]
    [#if FamilyName=="STM32F3"||FamilyName=="STM32L1"]
      [#if tabN==2]#t#t[#else]#t#t#t[/#if]__HAL_USB_WAKEUP_EXTI_CLEAR_FLAG();
      [#if tabN==2]#t#t[#else]#t#t#t[/#if]__HAL_USB_WAKEUP_EXTI_ENABLE_RISING_EDGE();
    [/#if]
    [#if FamilyName=="STM32F2"||FamilyName=="STM32F4"||FamilyName=="STM32F7"]
        [#if ipName?contains("_FS")]
            [#if tabN==2]#t#t[#else]#t#t#t[/#if]__HAL_USB_OTG_FS_WAKEUP_EXTI_CLEAR_FLAG();
            [#if tabN==2]#t#t[#else]#t#t#t[/#if]__HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_RISING_EDGE();
        [/#if]
        [#if ipName?contains("_HS")]
            [#if tabN==2]#t#t[#else]#t#t#t[/#if]__HAL_USB_OTG_HS_WAKEUP_EXTI_CLEAR_FLAG();
            [#if tabN==2]#t#t[#else]#t#t#t[/#if]__HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_RISING_EDGE();
        [/#if]
    [/#if]
    [#if ipName?contains("_HS")]
        [#if tabN==2]#t#t[#else]#t#t#t[/#if]__HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_IT();
    [#elseif ipName?contains("OTG_FS")&&FamilyName=="STM32F1"]
        [#if tabN==2]#t#t[#else]#t#t#t[/#if]__HAL_USB_OTG_FS_WAKEUP_EXTI_CLEAR_FLAG();
        [#if tabN==2]#t#t[#else]#t#t#t[/#if]__HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_RISING_EDGE();
        [#if tabN==2]#t#t[#else]#t#t#t[/#if]__HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_IT();
    [#elseif ipName?contains("OTG_FS")&&FamilyName=="STM32L4"]
        [#if tabN==2]#t#t[#else]#t#t#t[/#if]__HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_IT();
    [#elseif ipName?contains("_FS")]
              [#if tabN==2]#t#t[#else]#t#t#t[/#if]__HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_IT();
    [#else]
        [#if FamilyName=="STM32F1"]
            [#if tabN==2]#t#t[#else]#t#t#t[/#if]__HAL_USB_WAKEUP_EXTI_CLEAR_FLAG();
            [#if tabN==2]#t#t[#else]#t#t#t[/#if]__HAL_USB_WAKEUP_EXTI_ENABLE_RISING_EDGE();
            [#if tabN==2]#t#t[#else]#t#t#t[/#if]__HAL_USB_WAKEUP_EXTI_ENABLE_IT();
        [#else]
            [#if tabN==2]#t#t[#else]#t#t#t[/#if]__HAL_USB_WAKEUP_EXTI_ENABLE_IT();
        [/#if]
    [/#if]
[/#macro]
[#-- End macro generate USB wake-up interrupt code --]

[#macro generateCecRxBuffer configModelList methodName argumentName bufferType bufferSize]
  [#list configModelList as configModel]
    [#if configModel.isMWUsed=="false"]
      [#if configModel.ipName?contains("CEC")]
        [#if configModel.methods??] [#-- if the pin configuration contains a list of LibMethods--]
          [#assign methodList = configModel.methods]
        [#else]
          [#assign methodList = configModel.libMethod]
        [/#if]
        [#list methodList as method]
          [#if method.name==methodName]
            [#if method.status=="OK"]
              [#if method.arguments??]
                [#list method.arguments as fargument]
                  [#if fargument.genericType=="struct"][#-- hcec --]
                    [#list fargument.argument as argument]
                      [#if argument.genericType=="struct"][#-- Init --]
                        [#assign bufferName = ""]
                        [#list argument.argument as argument2]
                          [#if argument2.name==argumentName]
                            [#if argument2.value?? && argument2.value!="__NULL"]
                              [#assign bufferName = argument2.value]
                            [/#if]
                          [/#if]
                        [/#list]
                        [#if bufferName!="" && bufferSize!="" && bufferType!=""]
${bufferType} ${bufferName}[${bufferSize}];
                        [/#if]
                      [/#if]
                    [/#list]
                  [/#if]
                [/#list]
              [/#if]
            [/#if]
          [/#if]
        [/#list]
      [/#if]
    [/#if]
  [/#list]
[/#macro]

[#-- macro generateLLConfigModelCode --]

[#macro generateLLConfigModelCode configModel inst nTab index]
[#if configModel.methods??] [#-- if the pin configuration contains a list of LibMethods--]
    [#assign methodList = configModel.methods]
[#else]
    [#if configModel.methods??]
        [#assign methodList = configModel.libMethod]  
    [/#if]
[/#if]
[#assign writeConfigComments=false]
[#if methodList?? ]
[#list methodList as method]
    [#if method.status=="OK"][#assign writeConfigComments=true][/#if]
[/#list]
[#if writeConfigComments]
[#if configModel.comments??]#t#t/**${configModel.comments?replace("#t","#t#t")}#n#t#t*/[/#if]
[/#if]
    [#list methodList as method][#assign args = ""]
 [#assign errorCode = "HAL_OK"]
            [#if (method.name)?starts_with("ADV_LPBAM")]
               [#assign errorCode = "LPBAM_OK"]
            [/#if]
        [#if method.status=="OK"]           
                [#if method.arguments??]
                    [#list method.arguments as fargument][#compress]
                    [#if fargument.addressOf] [#assign adr = "&"][#else ][#assign adr = ""][/#if]
                    [#if fargument.cast??] [#assign adr = fargument.cast + adr][/#if][/#compress] 
                    [#if fargument.genericType == "struct"]
                        [#if fargument.context??]
                            [#if fargument.context=="global"]
                                [#if configModel.ipName=="DMA" || configModel.ipName=="BDMA" || config.ipName=="BDMA1"]
                                    [#assign instanceIndex = "_"+ configModel.dmaRequestName?lower_case]
                                [#else]
                                   [#-- [#assign instanceIndex = inst?replace(name,"")]--]
                                   [#if index??][#assign instanceIndex = index][#else][#if name??][#assign instanceIndex = inst?replace(name,"")][/#if][/#if]
                                   [#if configModel.ipName=="DFSDM" || configModel.ipName=="MDF" || configModel.ipName=="ADF"]
                                        [#assign instanceIndex = ""]
                                   [/#if]
                                [/#if]
                            [/#if]
                        [/#if]                     
                        [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#if fargument.status!="NULL"][#assign arg = "" + adr + fargument.name + instanceIndex][#else][#assign arg = "NULL"][/#if][#else][#if  fargument.status!="NULL"][#assign arg = "" + adr + fargument.name][#else][#assign arg = "NULL"][/#if][/#if]
                        [#-- [#assign arg = "" + adr + fargument.name] --]
                        [#if ((!method.name?contains("Init")&&fargument.context=="global")||(fargument.optional=="output"))]
                        [#else]
                        [#list fargument.argument as argument]	
                            [#if argument.genericType != "struct"]
                                [#if argument.mandatory]
                                [#if argument.value?? && argument.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"]
                                        [#assign argValue=argument.value?replace("$Index",instanceIndex)]
                                    [#else]
                                        [#assign argValue=argument.value]
                                    [/#if][#-- if global --]
                                    [#if argument.genericType=="Array" && argument.context!="globalConst" && argument.context!="globalInit"][#-- if genericType=Array --]
                                    [#if argument.arraySeparator?? && argument.arraySeparator!=""]
                                            [#assign valList = argument.value?split(argument.arraySeparator)]     
                                        [#else]
                                            [#assign valList = argument.value?split(":")]
                                        [/#if]
                                            [#assign i = 0]                                  
                                        [#list valList as val] 
                                            #t${argument.name}[${i}] = ${val};
                                            [#assign i = i+1]
                                        [/#list]
                                        [#assign argValue="&"+argument.name]
                                    [/#if] [#-- if genericType=Array --]
                                            
                                    [#if argument.value!="" && argument.value!="N/A"]
                                    [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name} = ${argValue};
                                    [#else]
                                    [#if nTab==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name} = [#if argument.value!="N/A"]${argValue}[/#if];
                                    [/#if]                                                                     
                                    [/#if]
                                    [#else] [#-- else argument.mandatory--]
                                      [#if fargument.name!="GPIO_InitStruct" && fargument.name!="GPIO_Init"]
                                            [#if argument.name=="Instance"][#-- if argument=Instance--]
                                              [#-- calculate the value of Instance argument if contains $Index --]
                                                [#if  (argument.value?? && argument.value!="__NULL") && (argument.value?contains("$Index"))]
                                                    [#assign instanceValue=argument.value?replace("$Index",index)]
                                                [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name} = ${instanceValue};
                                                [#else]
                                                   [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name} = [#if argument.value?? && argument.value!="__NULL"]${argument.value};[#else]${inst};[/#if]
                                                [/#if]
                                          [#else]
                                              [#if argument.status=="KO"]
                                                   [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]//${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name} = ${argument.value};                                        
                                              [/#if]
                                              [#if argument.value?? && argument.value!="__NULL"]
                                                   [#if argument.value!="N/A"][#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name} = ${argument.value};  [/#if]
                                              [/#if]                                    
                                          [/#if][#-- if argument=Instance--]                                
                                      [/#if]    
                                [/#if][#-- if argument.mandatory--]                                
                            [#else]
                            [#list argument.argument as argument2]
[#if argument2.genericType!="struct"]
                                [#if argument2.value?? && argument2.value!="__NULL"][#assign argValue=argument2.value][#else] [#assign argValue=""][/#if]
                                [#if argument2.mandatory]
                                    [#if argument2.value?? && argument2.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"][#assign argValue=argument2.value?replace("$Index",instanceIndex)][#else][#assign argValue=argument2.value][/#if]
                                    [#if argument2.genericType=="Array" && argument2.context!="globalConst" && argument2.context!="globalInit"][#-- if genericType=Array --] 
                                        [#if argument2.arraySeparator?? && argument2.arraySeparator!=""]
                                        [#assign valList = argument2.value?split(argument2.arraySeparator)]     
                                        [#else]
                                            [#assign valList = argument2.value?split(":")]
                                        [/#if]     
                                            [#assign i = 0]                                  
                                        [#list valList as val] 
#t${argument2.name}[${i}] = ${val};
                                            [#assign i = i+1]
                                        [/#list]
                                        [#assign argValue="&"+argument2.name+"[0]"]
                                    [/#if] [#-- if genericType=Array --]
                                    [#-- if argument is a global array --]
                                    [#if argument2.genericType=="Array" && (argument2.context=="globalConst" || argument2.context=="globalInit")][#-- if genericType=Array and gloabl--]                                        
                                        [#assign argValue="("+argument2.typeName +" *)"+argument2.name]
                                    [/#if]
                                    [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name}.${argument2.name} = ${argValue};                                    
                                    [/#if]
                               [#else] [#-- !argument.mandatory --]
                                    [#if argument2.status=="KO"]
                                        [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]//${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name}.${argument2.name} = ${argValue};
                                    [/#if]
                                    [#if argument2.status=="OK"]
                                    [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name}.${argument2.name} = ${argValue};
                                    [/#if]
                                [/#if][#-- if argument.mandatory --]
[#else]
[#list argument2.argument as argument3]
 [#if argument3.value?? && argument3.value!="__NULL"][#assign argValue=argument3.value][#else] [#assign argValue=""][/#if]
                                [#if argument3.mandatory]
                                    [#if argument3.value?? && argument3.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"][#assign argValue=argument3.value?replace("$Index",instanceIndex)][#else][#assign argValue=argument3.value][/#if]
                                    [#if argument3.genericType=="Array" && argument3.context!="globalConst" && argument3.context!="globalInit"][#-- if genericType=Array --] 
                                        [#if argument3.arraySeparator?? && argument3.arraySeparator!=""]
                                            [#assign valList = argument3.value?split(argument3.arraySeparator)]     
                                        [#else]
                                            [#assign valList = argument3.value?split(":")]
                                        [/#if]     
                                            [#assign i = 0]                                  
                                        [#list valList as val] 
#t${argument3.name}[${i}] = ${val};
                                            [#assign i = i+1]
                                        [/#list]
                                        [#assign argValue="&"+argument3.name+"[0]"]
                                    [/#if] [#-- if genericType=Array --]
                                    [#-- if argument is a global array --]
                                    [#if argument3.genericType=="Array" && (argument3.context=="globalConst" || argument3.context=="globalInit")][#-- if genericType=Array and gloabl--]                                        
                                        [#assign argValue="("+argument3.typeName +" *)"+argument3.name]
                                    [/#if]
                                    [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name}.${argument2.name}.${argument3.name} = ${argValue};                                    
                                    [/#if]
                               [#else] [#-- !argument.mandatory --]
                                    [#if argument3.status=="KO"]
                                        [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]//${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name}.${argument2.name}.${argument3.name} = ${argValue};
                                    [/#if]
                                    [#if argument3.status=="OK"]
                                    [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name}.${argument2.name}.${argument3.name} = ${argValue};
                                    [/#if]
                                [/#if][#-- if argument.mandatory --]
[/#list]
[/#if]
                            [/#list]
                            [/#if]
                        [/#list][#-- list  fargument.argument as argument--]
                        [/#if]
                    [#else][#-- if struct --] [#-- here--]
                    [#assign arg = ""] 
                        [#if fargument.status=="OK" && fargument.value?? && fargument.value!="__NULL"]
                            [#if name??][#assign argIndex = inst?replace(name,"")]  [/#if]
                                            [#if argIndex??]
                                                [#assign argValue=fargument.value?replace("$Index",argIndex)]
                                                [#if fargument.returnValue!="true"]
                                                    [#assign arg = "" + adr + argValue]
                                                [/#if]
                                            [#else]
                                                [#if fargument.returnValue!="true"]
                                                    [#assign arg = "" + adr + fargument.value]                                                
                                                [/#if]
                                            [/#if]                       
                        [/#if]
                    [/#if]
                    [#if args == "" && arg!=""][#assign args = args + arg ][#else][#if arg!=""][#assign args = args + ', ' + arg][/#if][/#if]
                    [/#list]
                    [#assign retval=""]
            [#list method.arguments as argument]
            [#if argument.returnValue=="true"]
                [#assign retval=argument.name]
            [/#if]
            [/#list]

            [#--[#if retval??&& retval!=""]
            [#if nTab==2]#t#t[#else]#t[/#if]${retval} = ${method.name}(${args});--]
            [#-- else --]
                    [#-- Check on HAL_OK --]
                        [#if method.returnHAL=="false"] [#-- update for LL test --]
            [#if nTab==2]#t#t[#else]#t[/#if]${method.name}(${args});
                        [#else]
                            [#-- [#if nTab==2]#t#t[#else]#t[/#if]${method.name}(${args});#n --]                            
                            [#if nTab==2]#t#t[#else]#t[/#if]if (${method.name}(${args}) != [#if method.returnHAL == "true"]${errorCode}[#else]${method.returnHAL}[/#if])
                            [#if nTab==2]#t#t[#else]#t[/#if]{
                            [#if nTab==2]#t#t[#else]#t[/#if]#tError_Handler();
                            [#if nTab==2]#t#t[#else]#t[/#if]}
                        [/#if]#n
            [#-- [/#if] --]
        [#else]
                    [#--[#if nTab==2]#t#t[#else]#t[/#if]${method.name}();#n --]
                        [#if method.returnHAL=="false"][#-- update for LL test --]
            [#if nTab==2]#t#t[#else]#t[/#if]${method.name}();
                        [#else]
                            [#-- [#if nTab==2]#t#t[#else]#t[/#if]${method.name}(${args});#n --]
                            [#if nTab==2]#t#t[#else]#t[/#if]if (${method.name}() != [#if method.returnHAL == "true"]${errorCode}[#else]${method.returnHAL}[/#if])
                            [#if nTab==2]#t#t[#else]#t[/#if]{
                            [#if nTab==2]#t#t[#else]#t[/#if]#tError_Handler();
                            [#if nTab==2]#t#t[#else]#t[/#if]}
                        [/#if]#n
                [/#if]			
        [/#if]
        [#if method.status=="KO"]
#n [#if nTab==2]#t#t[#else]#t[/#if]//!!! ${method.name} is commented because some parameters are missing
            [#if method.arguments??]			
                [#list method.arguments as fargument]
                    [#if fargument.addressOf] [#assign adr = "&"][#else ] [#assign adr = ""][/#if]
                    [#if fargument.cast??] [#assign adr = fargument.cast + adr][/#if]
                    [#if fargument.genericType == "struct"][#assign arg = "" + adr + fargument.name]
                        [#if fargument.optional == "output"]
                                [#assign arg = "" + adr + fargument.name]
                                [#if fargument.cast??] [#assign arg = fargument.cast + arg][/#if]
                        [/#if]
                                        [#if fargument.context?? && fargument.optional!="output"]                   
                                            [#if fargument.context=="global"]
                                                [#if configModel.ipName=="DMA" || configModel.ipName=="BDMA"]
                                                [#assign instanceIndex = "_"+ configModel.dmaRequestName?lower_case]
                                                [#else]
                                                [#assign instanceIndex = inst?replace(name,"")]
                                                [#if configModel.ipName=="DFSDM" || configModel.ipName=="MDF" || configModel.ipName=="ADF"]
                                                    [#assign instanceIndex = ""]
                                                [/#if]
                                                [/#if]
                                            [/#if]
                                        [/#if]              
                        [#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"][#assign arg = "" + adr + fargument.name + instanceIndex][#else][#assign arg = "" + adr + fargument.name][/#if]
                        [#if (!method.name?contains("Init")&&fargument.context=="global")]
                        [#else]
                        [#list fargument.argument as argument]	
                                [#if argument.genericType != "struct"]
                                [#if argument.mandatory && argument.value?? && argument.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"][#assign argValue=argument.value?replace("$Index",instanceIndex)][#else][#assign argValue=argument.value][/#if]
                                    [#if nTab==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name} = ${argValue};
                                 [#else]
                                    [#if argument.name=="Instance"]
                                        [#if nTab==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name} = ${inst};
                                    [/#if]                                
                                [/#if]
                            [#else]
                            [#list argument.argument as argument1]
                                [#if argument1.mandatory && argument1.value?? && argument1.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"][#assign argValue=argument1.value?replace("$Index",instanceIndex)][#else][#assign argValue=argument1.value][/#if]
                                [#if nTab==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if]${link}${argument.name}.${argument1.name} = ${argValue};
                                [/#if]
                            [/#list]
                            [/#if]
                            [/#list]
[/#if]
                                      [/#if][#-- if argument != struct --]
                    [#if args == ""][#assign args = args + arg ]
                    [#else][#assign args = args + ', ' + arg]
                                        [/#if]
                                [/#list]
                                [#if nTab==2]#t#t[#else]#t[/#if]#t//${method.name}(${args});
                        [#else] [#-- if method without argument --]
                               [#-- [#if nTab==2]#t#t[#else]#t[/#if]${method.name}()#n; --]
                            [#if method.returnHAL=="false"]
                                [#if nTab==2]#t#t[#else]#t[/#if]${method.name}();
                            [#else]
                                [#-- [#if nTab==2]#t#t[#else]#t[/#if]${method.name}(${args});#n --]
                                [#if nTab==2]#t#t[#else]#t[/#if]if (${method.name}() != [#if method.returnHAL == "true"]${errorCode}[#else]${method.returnHAL}[/#if])
                                [#if nTab==2]#t#t[#else]#t[/#if]{
                                [#if nTab==2]#t#t[#else]#t[/#if]#tError_Handler();
                                [#if nTab==2]#t#t[#else]#t[/#if]}
                            [/#if]#n
                        [/#if]
                [/#if]
        [/#list]
[/#if]
[#-- assign instanceIndex = "" --]
 [#-- else there is no LibMethod to call--]
[/#macro]
[#-- End macro generateLLConfigModelCode --]

[#-- New --]
[#-- Start macro callLibMethod --]
[#macro callLibMethod CLmethod configModelRef instRef nTabRef indexRef argumentValue]
[#if CLmethod??]
[#--assign CLmethod = argumentRef.refMethod--]
        [#if CLmethod.status=="OK"]

                [#if CLmethod.arguments??][#assign intArgs = ""]
                    [#list CLmethod.arguments as fargument][#compress]
                    [#if fargument.addressOf] [#local adr = "&"][#else ][#local adr = ""][/#if]
                    [#if fargument.cast??] [#assign adr = fargument.cast + adr][/#if][/#compress] 
                    [#if fargument.genericType == "struct"]{
                         [#if fargument.optional == "output"]
                                [#assign arg = "" + adr + fargument.name] 
                                [#if fargument.cast??] [#assign arg = fargument.cast + arg][/#if]
                        [/#if]
                        [#if fargument.context?? && fargument.optional!="output"]
                            [#if fargument.context=="global"]
                                [#if config.ipName=="DMA" || config.ipName=="BDMA"]
                                    [#local instanceIndex = "_"+ config.dmaRequestName?lower_case]
                                [#else]
                                   [#-- [#local instanceIndex = instRef?replace(name,"")]--]
                                   [#if indexRef??][#local instanceIndex = indexRef][#else][#if name??][#local instanceIndex = instRef?replace(name,"")][/#if][/#if]
                                                [#if configModelRef.ipName=="DFSDM" || configModel.ipName=="MDF" || configModel.ipName=="ADF"]
                                                    [#local instanceIndex = ""]
                                                [/#if]
                                [/#if]
                            [/#if]
                        [/#if]                     
                        [#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"][#if fargument.status!="NULL"][#local arg = "" + adr + fargument.name + instanceIndex][#else][#local arg = "NULL"][/#if][#else][#if  fargument.status!="NULL"][#local arg = "" + adr + fargument.name][#else][#local arg = "NULL"][/#if][/#if]
                        [#-- [#local arg = "" + adr + fargument.name] --]
                        [#if ((!CLmethod.name?contains("Init")&&fargument.context=="global")||(fargument.optional=="output"))]
                        [#else]
                            [#local index1 =1] [#-- index of argument struct level1 --]
                        [#list fargument.argument as argument]	

                            [#if argument.genericType != "struct"]
                                [#if argument.mandatory]
                                [#if argument.value?? && argument.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]
                                        [#local argValue=argument.value?replace("$Index",instanceIndex)]
                                    [#else]
                                        [#local argValue=argument.value]
                                    [/#if][#-- if global --]
                                    [#if argument.genericType=="Array" && argument.context!="globalConst" && argument.context!="globalInit"][#-- if genericType=Array --]
                                    [#if argument.arraySeparator?? && argument.arraySeparator!=""]
                                        [#local valList = argument.value?split(argument.arraySeparator)]     
                                    [#else]
                                        [#local valList = argument.value?split(":")]
                                    [/#if]
                                            [#local i = 0]                                  
                                        [#list valList as val] 
                                            [#if argument.base == "10"]
#t${argument.name}[${i}] = ${val};
                                            [#else]
#t${argument.name}[${i}] = 0x${val};
                                            [/#if]
                                            [#local i = i+1]
                                        [/#list]
                                        [#local argValue="&"+argument.name]                                    
                                    [/#if] [#-- if genericType=Array --]
                                    [#-- if argument is a global array --]
                                    [#if argument.genericType=="Array" && (argument.context=="globalConst" || argument.context=="globalInit")][#-- if genericType=Array and gloabl--]                                        
                                        [#assign argValue="("+argument.typeName +" *)"+argument.name]
                                    [/#if]
                                    [#if argument.value!="" && argument.value!="N/A"]
                                    [#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"][#local varName=fargument.name +"." +instanceIndex][#else][#local varName=fargument.name][/#if]
                                        [#local indicator = varName+"."+argument.name+" = "+argValue+" "]
                                        [#local indicatorName = varName+"."+argument.name]
                                        [#if !listofDeclaration?contains(indicator)][#-- if not repeted --]
                                            [#if nTabRef==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"][#local varName=fargument.name +"." +instanceIndex]${fargument.name}${instanceIndex}[#else][#local varName=fargument.name]${fargument.name}[/#if].${argument.name} = ${argValue};                                        
                                            [#local listofDeclaration = listofDeclaration?replace(indicatorName+" =","")]
                                            [#local listofDeclaration = listofDeclaration +", "+ varName+"."+argument.name+" = "+argValue+" "]                                                                                 
                                        [/#if]
                                    [#else]
                                    [#if nTabRef==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = [#if argument.value!="N/A"]${argValue}[/#if];
                                    [/#if]                                                                     
                                    [/#if]
                                    [#else] [#-- else argument.mandatory--]
                                      [#if fargument.name!="GPIO_InitStruct" && fargument.name!="GPIO_Init"]
                                            [#if argument.name=="Instance"][#-- if argument=Instance--]
                                              [#-- calculate the value of Instance argument if contains $Index --]
                                                [#if  (argument.value??&& argument.value!="__NULL") && (argument.value?contains("$Index"))]
                                                    [#local instanceValue=argument.value?replace("$Index",indexRef)]
[#if instanceIndex??&&fargument.context=="global"][#local varName=fargument.name +instanceIndex][#else][#local varName=fargument.name][/#if]
                                                    [#local indicator = varName+"."+argument.name+" = "+instanceValue+" "]
                                                    [#if !listofDeclaration?contains(indicator)]    [#-- if not repeted --]
                                                    [#if nTabRef==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = ${instanceValue};
                                                            [#local listofDeclaration = listofDeclaration +", "+ indicator]

                                                    [/#if]
                                                [#else]
[#if instanceIndex??&&fargument.context=="global"][#local varName=fargument.name+instanceIndex][#else][#local varName=fargument.name][/#if] [#if argument.value?? && argument.value!="__NULL"][#local argv =argument.value][#else][#local argv=instRef][/#if]
                                                   [#local indicator = varName+"."+argument.name+" = "+argv+" "]
                                                   [#if !listofDeclaration?contains(indicator)] [#-- if not repeted --]
                                                    [#if nTabRef==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = [#if argument.value?? && argument.value!="__NULL"]${argument.value};[#else]${instRef};[/#if]
                                                            [#local listofDeclaration = listofDeclaration +", "+ indicator]

                                                            [#if index1 == fargument.argument?size]
#n
                                                            [/#if]

                                                   [/#if]
                                                [/#if]
                                          [#else]
                                              [#if argument.status=="KO"]
                                                   [#if nTabRef==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]//${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = ${argument.value};                                        
                                              [/#if]
                                              [#if argument.value?? && argument.value!="__NULL"]
                                                   [#if argument.value!="N/A"][#if nTabRef==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = ${argument.value};  [/#if]
 [#if index1 == fargument.argument?size]
#n
                                                            [/#if]
                                              [/#if]                                    
                                          [/#if][#-- if argument=Instance--]                                
                                      [/#if]    
                                [/#if][#-- if argument.mandatory--]                                
                            [#else]
                            [#local index2=0]
                            [#list argument.argument as argument2]
[#if argument2.genericType!="struct"] 
                                [#if argument2.value?? && argument2.value!="__NULL"][#local argValue=argument2.value][#else] [#local argValue=""][/#if]
                                [#if argument2.mandatory]
                                    [#if argument2.value?? && argument2.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"][#local argValue=argument2.value?replace("$Index",instanceIndex)][#else][#local argValue=argument2.value][/#if]
                                    [#if argument2.genericType=="Array" && argument2.context!="globalConst" && argument2.context!="globalInit"][#-- if genericType=Array --]
                                        [#if argument2.arraySeparator?? && argument2.arraySeparator!=""]
                                        [#local valList = argument2.value?split(argument2.arraySeparator)]     
                                        [#else]
                                            [#local valList = argument2.value?split(":")]
                                        [/#if]
                                            [#local i = 0]                                  
                                        [#list valList as val] 
                                            [#if argument2.base == "10"]
#t${argument2.name}[${i}] = ${val};
                                            [#else]
#t${argument2.name}[${i}] = 0x${val};
                                            [/#if]
                                            [#local i = i+1]
                                        [/#list]
                                        [#local argValue="&"+argument2.name+"[0]"]
                                    [/#if] [#-- if genericType=Array --]
                                    [#-- if argument is a global array --]
                                    [#if argument2.genericType=="Array" && (argument2.context=="globalConst" || argument2.context=="globalInit")][#-- if genericType=Array and gloabl--]                                        
                                        [#assign argValue="("+argument2.typeName +" *)"+argument2.name]
                                    [/#if]
[#if instanceIndex??&&fargument.context=="global"][#local varName=fargument.name +instanceIndex][#else][#local varName=fargument.name][/#if]
                                                    [#local indicator = varName+"."+argument.name+"."+argument2.name+" = "+argValue+" "]
                                                    [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]
                                                        [#if nTabRef==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name} = ${argValue};                                    

                                                        [#if index2 == argument.argument?size]
#n [#-- add space line at the end of argument setting --] 
                                                        [/#if]
                                                            [#local listofDeclaration = listofDeclaration +", "+ indicator]
                                                    [/#if]
                                    [/#if]
                               [#else] [#-- !argument.mandatory --]
                                    [#if argument2.status=="KO"]
                                        [#if nTabRef==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]//${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name} = ${argValue};
                                    [/#if]
                                    [#if argument2.status=="OK"]
[#if instanceIndex??&&fargument.context=="global"][#local varName=fargument.name +instanceIndex][#else][#local varName=fargument.name][/#if]
                                         [#local indicator = varName+"."+argument.name+"."+argument2.name+" = "+argValue+" "]
                                         [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]   
                                            [#if nTabRef==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name} = ${argValue};
                                            [#local listofDeclaration = listofDeclaration +", "+ indicator]                                            
                                         [/#if]
                                    [/#if]
                                [/#if][#-- if argument.mandatory --]
[#else]
[#list argument2.argument as argument3]
 [#if argument3.value?? && argument3.value!="__NULL"][#local argValue=argument3.value][#else] [#local argValue=""][/#if]
                                [#if argument3.mandatory]
                                    [#if argument3.value?? && argument3.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"][#local argValue=argument3.value?replace("$Index",instanceIndex)][#else][#local argValue=argument3.value][/#if]
                                    [#if argument3.genericType=="Array" && argument3.context!="globalConst" && argument3.context!="globalInit"][#-- if genericType=Array --] 
                                        [#if argument3.arraySeparator?? && argument3.arraySeparator!=""]
                                            [#local valList = argument3.value?split(argument3.arraySeparator)]     
                                        [#else]
                                            [#local valList = argument3.value?split(":")]
                                        [/#if]     
                                            [#local i = 0]                                  
                                        [#list valList as val] 
                                            [#if argument3.base == "10"]
#t${argument3.name}[${i}] = ${val};
                                            [#else]
#t${argument3.name}[${i}] = 0x${val};
                                            [/#if]
                                            [#local i = i+1]
                                        [/#list]
                                        [#local argValue="&"+argument3.name+"[0]"]
                                    [/#if] [#-- if genericType=Array --]
                                    [#-- if argument is a global array --]
                                    [#if argument3.genericType=="Array" && (argument3.context=="globalConst" || argument3.context=="globalInit")][#-- if genericType=Array and gloabl--]                                        
                                        [#assign argValue="("+argument3.typeName +" *)"+argument3.name]
                                    [/#if]
[#if instanceIndex??&&fargument.context=="global"][#local varName=fargument.name +instanceIndex][#else][#local varName=fargument.name][/#if]
                                         [#local indicator = varName+"."+argument.name+"."+argument2.name+"."+argument3.name+" = "+argValue+ " "]
                                         [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]                                      
                                            [#if nTabRef==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name}.${argument3.name} = ${argValue};                                    
                                            [#local listofDeclaration = listofDeclaration +", "+ indicator]
                                         [/#if]                                       [/#if]
                               [#else] [#-- !argument.mandatory --]
                                    [#if argument3.status=="KO"]
[#if instanceIndex??&&fargument.context=="global"][#local varName=fargument.name +instanceIndex][#else][#local varName=fargument.name][/#if]
                                         [#local indicator = varName+"."+argument.name+"."+argument2.name+"."+argument3.name+" = "+argValue+" "] 
                                         [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]  
                                            [#if nTabRef==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name}.${argument3.name} = ${argValue};
                                            [#local listofDeclaration = listofDeclaration +", "+ indicator]
                                         [/#if]
                                    [/#if]
                                    [#if argument3.status=="OK"]
                                    [#if nTabRef==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name}.${argument3.name} = ${argValue};
                                    [/#if]
                                [/#if][#-- if argument.mandatory --]
[/#list]
[/#if]
[#local index2=index2 + 1]
                            [/#list]
                            [/#if]
[#local index1 =index1 + 1]
                        [/#list][#-- list  fargument.argument as argument--]
                        [/#if]
                    [#else][#-- if struct --]
                    [#local arg = ""]
                        [#if fargument.status=="OK" && fargument.value?? && fargument.value!="__NULL"]
                            [#if name??][#local argIndex = instRef?replace(name,"")]  [/#if]
                                            [#if argIndex??] 

                                                [#local argValue=fargument.value?replace("$Index",argIndex)]
                                                [#if fargument.returnValue!="true"]
                                                    [#local arg = "" + adr + argValue]
                                                [/#if]
                                            [#else]
                                                [#if fargument.returnValue!="true"]
                                                    [#local arg = "" + adr + fargument.value]                                                

                                                [/#if]
                                            [/#if]    
                        [#else] [#if fargument.status=="NULL"][#local arg = "" + adr + "NULL"] [/#if]                    
                        [/#if]
                    [/#if]
                    [#if intArgs == "" && arg!=""][#local intArgs = intArgs + arg ][#else][#if arg!=""][#local intArgs = intArgs + ', ' + arg][/#if][/#if]
                    [/#list]
                    [#local retval=""]
            [#list CLmethod.arguments as argument]
            [#if argument.returnValue=="true"]
                [#local retval=argument.name]
            [/#if]
            [/#list]
[#list methodList as method]
[#if (method.callMethod?? && !(method.callMethod)) || (S_FATFS_SDIO?? && (instRef=="SDIO" || instRef?starts_with("SDMMC")))] [#-- if HAL_SD_Init  and SDIO is used with FATFS--]
[#else]		    
[#--[#if nTab==2]#t#t[#else]#t[/#if]${CLmethod.name}(${intArgs});#n--]
[#assign argumentValue = CLmethod.name+"("+intArgs+")"] [#-- New --]
        [#-- delete call method--]
[/#if]
[/#list]
            [#else]
[#assign argumentValue = CLmethod.name+"()"]
        [#-- delete call method--]
        [/#if]			
        [/#if]
        [#if CLmethod.status=="KO"]
#n [#if nTabRef==2]#t#t[#else]#t[/#if]//!!! ${CLmethod.name} is commented because some parameters are missing
            [#if CLmethod.arguments??]	
                [#list CLmethod.arguments as fargument]
                    [#if fargument.addressOf] [#local adr = "&"][#else ] [#local adr = ""][/#if]
                    [#if fargument.cast??] [#assign adr = fargument.cast + adr][/#if]
                        [#if fargument.genericType == "struct"][#local arg = "" + adr + fargument.name]
                                        [#if fargument.context??]                   
                                            [#if fargument.context=="global"]
                                                [#if config.ipName=="DMA" || config.ipName=="BDMA" || config.ipName=="BDMA1"]
                                                [#local instanceIndex = "_"+ config.dmaRequestName?lower_case]
                                                [#else]
                                               [#if name??] [#local instanceIndex = instRef?replace(name,"")][/#if]
                                                [#if configModelRef.ipName=="DFSDM" || configModel.ipName=="MDF" || configModel.ipName=="ADF"]
                                                    [#local instanceIndex = ""]
                                                [/#if]                
                                                [/#if]
                                            [/#if]
                                        [/#if]              
                        [#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"][#local arg = "" + adr + fargument.name + instanceIndex][#else][#local arg = "" + adr + fargument.name][/#if]
                        [#if (!CLmethod.name?contains("Init")&&fargument.context=="global")]
                        [#else]
                        [#list fargument.argument as argument]	
                                [#if argument.genericType != "struct"]
                                [#if argument.mandatory && argument.value?? && argument.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"][#local argValue=argument.value?replace("$Index",instanceIndex)][#else][#local argValue=argument.value][/#if]
                                    [#if nTabRef==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = ${argValue};
                                 [#else]
                                    [#if argument.name=="Instance"]
                                        [#if nTabRef==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = ${instRef};
                                    [/#if]                                
                                [/#if]
                            [#else]
                            [#list argument.argument as argument1]
                                [#if argument1.mandatory && argument1.value?? && argument1.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"][#local argValue=argument1.value?replace("$Index",instanceIndex)][#else][#local argValue=argument1.value][/#if]
                                [#if nTabRef==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument1.name} = ${argValue};
                                [/#if]
                            [/#list]
                            [/#if]
                            [/#list]
[/#if]
                                        [#else] [#-- if argument != struct --]
 [#if name??][#local argIndex = instRef?replace(name,"")]  
                                            [#local argIndex = instRef?replace(name,"")] 
[/#if]
                                            [#if argIndex??]
                                                [#local argValue=fargument.value?replace("$Index",argIndex)]
                                                [#local arg = "" + adr + argValue]
                                            [#else]
                                                [#local arg = "" + adr + fargument.value]                                                
                                            [/#if]
                                        [/#if]
                    [#if intArgs == ""][#local intArgs = intArgs + arg ]
                    [#else][#local intArgs = intArgs + ', ' + arg]
                                        [/#if]
                                [/#list]
                                [#if nTabRef==2]#t#t[#else]#t[/#if]#t//${CLmethod.name}(${intArgs});[#local argumentValue = CLmethod.name+"}("+intArgs+")"]
                        [#else] [#-- if CLmethod without argument --]
[#assign argumentValue = CLmethod.name+"()"]                            
                               [#--[#if nTabRef==2]#t#t[#else]#t[/#if]${CLmethod.name}();--]
#n
                        [/#if]
                [/#if]
                [/#if]
[/#macro]
[#--End macro callLibMethod --]

[#-- -------------------- Common Macro ------------- --]
[#-- macro generate service code for MspInit/MspDeInit Start--]
[#macro generateServiceCode ipName serviceType modeName instHandler tabN IPData]
    [#if serviceType=="Init"]
        [#--assign initService = getInitServiceMode(ipName,IPData)--]
        [#assign initService = {"test0":"test1"}]       
        [#if IPData.halInstanceName==ipName]            
            [#if IPData.initServices??]
                [#--assign initService = IPData.initServices--]
            [/#if]
        [/#if]
    [#else][#-- If DeInit --]
        [#assign initService = getDeInitServiceMode(ipName,IPData)]
    [/#if]
    [#assign gpioExist = false]
    [#assign dmaExist = false]
    [#assign nvicExist = false]
    [#if IPData.initServices?? && IPData.initServices.entrySet??]
        [#list IPData.initServices.entrySet() as entry]
            [#if entry.key=="dma" && !modeName?contains("DFSDM") && !ipName?starts_with("GPDMA")&& !ipName?starts_with("LPDMA")]
                [#assign dmaExist = true]
            [/#if]
            [#if entry.key=="nvic" && IPData.initServices.nvic?size!=0 && !modeName?contains("DFSDM_Filter")]
                [#assign nvicExist = true]
            [/#if]
            [#if entry.key=="gpio"]
                [#assign gpioExist = true]
            [/#if]            
        [/#list]
    [/#if]    
    [#if serviceType=="Init"] 
        [#if !ipName?contains("I2C")&& !ipName?contains("USB")&& !ipName?contains("ICACHE")] [#-- if not I2C --]
            [#if IPData.initServices.clock??]
                [#if IPData.initServices.clock!="none"]
                    [#if FamilyName=="STM32F1" && ipName=="RTC"]
[#if usedDriverFlag?? && !usedDriverFlag?contains("LL")]
                        #t#tHAL_PWR_EnableBkUpAccess();
                        #t#t/* Enable BKP CLK enable for backup registers */
                        #t#t__HAL_RCC_BKP_CLK_ENABLE();    
                        [#else]
                        #t#tLL_PWR_EnableBkUpAccess();
                        #t#t/* Enable BKP CLK enable for backup registers */
                        #t#tLL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_BKP);
                        [/#if]                   
                    [/#if]
[#if tabN == 2]#t[/#if]#t/* Peripheral clock enable */ 
                    [#list IPData.initServices.clock?split(';') as clock]
                        [#--[#if ipvar.clkCommonResource.entrySet()?contains(clock?trim)]#t#t${clock?trim?replace("__","")?replace("_ENABLE","")}_ENABLED++;
                            #t#tif(${clock?trim?replace("__","")?replace("_ENABLE","")}_ENABLED==1){          
                            #t#t#t${clock?trim}();
                            [#if ipvar.clkCommonResource.entrySet()?contains(clock?trim)]#t#t}[/#if]  
                        [#else]--]
[#if tabN == 2]#t[/#if]#t${clock?trim}[#if !clock?contains('(')]()[/#if];
                        [#--[/#if]--][#-- remove control on common clock for sevral IP instances--]
                    [/#list]
                [/#if]
            [#else]
[#if tabN == 2]#t[/#if]#t/* Peripheral clock enable */
[#if tabN == 2]#t[/#if]#t__HAL_RCC_${ipName}_CLK_ENABLE(); 
            [/#if]
        [/#if] [#-- if not I2C --]
    [#else]  [#-- serviceType = deInit --]     
        [#if IPData.initServices.clock??]
            [#if IPData.initServices.clock!="none"]
[#if tabN == 2]#t[/#if]#t/* Peripheral clock disable */
               [#list IPData.initServices.clock?split(';') as clock]     
                    [#if ipvar.clkCommonResource.entrySet()?contains(clock?trim)]#t#t${clock?trim?replace("__","")?replace("_ENABLE","")}_ENABLED--;
[#if tabN == 2]#t[/#if]#tif(${clock?trim?replace("__","")?replace("_ENABLE","")}_ENABLED==0){       
#t#t#t${clock?replace("ENABLE","DISABLE")?trim}(); 
                        [#if ipvar.clkCommonResource.entrySet()?contains(clock?trim)]#t#t}[/#if] 
                    [#else]
#t#t${clock?replace("ENABLE","DISABLE")?trim}();
                    [/#if]
                [/#list]
            [/#if]
        [#else]
            [#if ipName?contains("WWDG") && (DIE=="DIE415" || DIE=="DIE435")]
                [#-- Orca and LittleOrca window watchdog clock disable don't work --]
            [#else]
#t#t/* Peripheral clock disable */
#t#t__HAL_RCC_${ipName}_CLK_DISABLE();  
            [/#if]
        [/#if]
    [/#if]
    [#if gpioExist]
#t[@generateConfigCode ipName=ipName type=serviceType serviceName="gpio" instHandler=instHandler tabN=tabN IPData1=IPData/]
    [/#if]
[#-- if I2C clk_enable should be after GPIO Init Begin --]
    [#if serviceType=="Init" && (ipName?contains("I2C")||ipName?contains("USB"))] 
        [#if IPData.initServices.clock??]
            [#if IPData.initServices.clock!="none"]
[#if tabN == 2]#t[/#if]#t/* Peripheral clock enable */
                [#list IPData.initServices.clock?split(';') as clock]
                    [#if ipvar?? && ipvar.clkCommonResource.entrySet()?contains(clock?trim)]#t#t${clock?trim?replace("__","")?replace("_ENABLE","")}_ENABLED++;
#t#tif(${clock?trim?replace("__","")?replace("_ENABLE","")}_ENABLED==1){          
#t#t#t${clock?trim}[#if !clock?contains('(')]()[/#if];
                        [#if ipvar?? && ipvar.clkCommonResource.entrySet()?contains(clock?trim)]#t#t}[/#if]  
                    [#else]
[#if tabN == 2]#t[/#if]#t${clock?trim}[#if !clock?contains('(')]()[/#if];
                    [/#if]        
                [/#list]
            [/#if]
        [#else]
#t#t/* Peripheral clock enable */
[#if tabN == 2]#t[/#if]#t__HAL_RCC_${ipName}_CLK_ENABLE(); 
        [/#if]
    [/#if]
[#-- if I2C clk_enable should be after GPIO Init End --]    
[#if serviceType=="Init"] 
    [#if dmaExist]#n[#if tabN == 2]#t[/#if]#t/* ${ipName} DMA Init */
[#-- DMA Configuration --]
#t[@generateConfigCode ipName=ipName type=serviceType serviceName="dma" instHandler=instHandler tabN=tabN IPData1=IPData/]
    [/#if]
[#-- bug 322189 Init--]
[#if ipName?contains("OTG_FS")&&(FamilyName=="STM32L4"||FamilyName=="STM32U5")]
#n#t#t/* Enable VDDUSB */
#t#tif(__HAL_RCC_PWR_IS_CLK_DISABLED())
#t#t{
#t#t#t__HAL_RCC_PWR_CLK_ENABLE();

#t#t#tHAL_PWREx_EnableVddUSB();

#t#t#t__HAL_RCC_PWR_CLK_DISABLE();
#t#t}
#t#telse
#t#t{
#t#t#tHAL_PWREx_EnableVddUSB();
#t#t}
[/#if]
[#if ipName?contains("OTG_HS")&&FamilyName=="STM32U5"]
#n#t#t/* Enable VDDUSB */
  #t#tif(__HAL_RCC_PWR_IS_CLK_DISABLED())
  #t#t{
    #t#t#t__HAL_RCC_PWR_CLK_ENABLE();
    
    #t#t#tHAL_PWREx_EnableVddUSB();
    #n#t#t#t/*configure VOSR register of USB*/
    #t#t#tHAL_PWREx_EnableUSBHSTranceiverSupply();
    
    #t#t#t__HAL_RCC_PWR_CLK_DISABLE();
  #t#t}
  #t#telse
  #t#t{
    #t#t#tHAL_PWREx_EnableVddUSB();
    #n#t#t#t/*configure VOSR register of USB*/
    #t#t#tHAL_PWREx_EnableUSBHSTranceiverSupply();
  #t#t}
#n#t#t/*Configuring the SYSCFG registers OTG_HS PHY*/
#t#t/*OTG_HS PHY enable*/
#t#t#tHAL_SYSCFG_EnableOTGPHY(SYSCFG_OTG_HS_PHY_ENABLE);
[/#if]
[#-- bug 322189 Init End--]
    [#if nvicExist]
        [#if IPData.initServices??&&IPData.initServices.nvic??&&IPData.initServices.nvic?size>0]
          [#assign codeInMspInit = false]
          [#list IPData.initServices.nvic as initVector]
            [#if initVector.codeInMspInit]
              [#assign codeInMspInit = true]
              [#break]
            [/#if]
          [/#list]
        [/#if]
  
   
    [#if IPData.initServices??]
[#if IPData.initServices.EnableCode??]
        [#assign GenerateNvicEnable = true]
    [/#if]
 [/#if]


        [#if IPData.initServices.nvic??&&IPData.initServices.nvic?size>0]
           [#if codeInMspInit || ipName?contains("USB")]
           [#-- Always generate comment for USB: it is not worth the trouble to compute when it is really needed --]
#n[#if tabN == 2]#t[/#if]#t/* ${ipName} interrupt Init */
           [/#if]
           [#if ipName?contains("USB")]
                [#-- WorkAround for USB low power and remap macro--]
                [#if USB_interruptRemapMacro??]
#t#t${USB_interruptRemapMacro};
                [/#if]
                [#list IPData.initServices.nvic as initVector]
                  [#if !initVector.vector?contains("WKUP") && !initVector.vector?contains("WakeUp") && initVector.codeInMspInit]
#t#tHAL_NVIC_SetPriority(${initVector.vector}, ${initVector.preemptionPriority}, ${initVector.subPriority});
[#if GenerateNvicEnable]
#t#tHAL_NVIC_EnableIRQ(${initVector.vector});
                  [/#if][/#if]
                [/#list]
                [#assign lowPower = "no"]
                [#list IPData.initServices.nvic as initVector]
                   [#if (instHandler=="hpcd") && (initVector.vector?contains("WKUP") || initVector.vector?contains("WakeUp") || (((initVector.vector == "USB_IRQn")||(initVector.vector == "OTG_FS_IRQn")||(initVector.vector == "USB_LP_IRQn")) && USB_INTERRUPT_WAKEUP??))]
                      [#assign lowPower = "yes"]
                   [/#if]
                [/#list]
                [#if lowPower == "yes"]
                  [#assign codeInMspInit = false]
                  [#assign wakeupVector = false]
                  [#list IPData.initServices.nvic as initVector]
                      [#if initVector.vector?contains("WKUP") || initVector.vector?contains("WakeUp")]
                          [#assign wakeupVector = true]
                          [#if initVector.codeInMspInit]
                            [#assign codeInMspInit = true]
                            [#break]
                          [/#if]
                      [/#if]
                  [/#list]
                  [#-- Even if init code is in MX_NVIC_Init, if there is no specific USB wake-up interrupt, some code needs to be generated here --]
                  [#if codeInMspInit || !wakeupVector]
#t#tif(hpcd->Init.low_power_enable == 1)
#t#t{
                    [@common.generateUsbWakeUpInterrupt ipName=ipName tabN=3/]
                    [#list IPData.initServices.nvic as initVector]
                       [#if initVector.vector?contains("WKUP") || initVector.vector?contains("WakeUp")]
#t#t#tHAL_NVIC_SetPriority(${initVector.vector}, ${initVector.preemptionPriority}, ${initVector.subPriority});
[#if GenerateNvicEnable]
#t#t#tHAL_NVIC_EnableIRQ(${initVector.vector});
                      [/#if] [/#if]
                    [/#list]
#t#t}
                  [/#if]
                [/#if]
           [#else]
              [#list IPData.initServices.nvic as initVector]
                [#if initVector.codeInMspInit]
                    [#if IPData.usedDriver == "HAL"]                
#t#tHAL_NVIC_SetPriority(${initVector.vector}, ${initVector.preemptionPriority}, ${initVector.subPriority});
[#if GenerateNvicEnable]
#t#tHAL_NVIC_EnableIRQ(${initVector.vector});
[/#if]
                    [#else]
                        [#if !NVICPriorityGroup??]
#tNVIC_SetPriority(${initVector.vector}, ${initVector.preemptionPriority});
                        [#else]
#tNVIC_SetPriority(${initVector.vector}, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),${initVector.preemptionPriority}, ${initVector.subPriority}));
                        [/#if]
[#if GenerateNvicEnable]
#tNVIC_EnableIRQ(${initVector.vector});
                    [/#if][/#if]
                [/#if]
              [/#list]
           [/#if]
        [/#if]
    [/#if]

    [#else] [#-- else serviceType = DeInit --]
 [#--assign service = getInitServiceMode(ipName,IPData)--]
[#assign service = ""]
        [#if IPData.halInstanceName==ipName]
            [#assign service = {"test0":"test1"}]
            [#if IPData.initServices??]
                [#assign service = IPData.initServices]
            [/#if]
        [/#if]
[#-- bug 322189 DeInit--]
[#if ipName?contains("OTG_FS")&&FamilyName=="STM32L4"]
#n#t#t/* Disable VDDUSB */
#t#tif(__HAL_RCC_PWR_IS_CLK_DISABLED())
#t#t{
#t#t#t__HAL_RCC_PWR_CLK_ENABLE();

#t#t#tHAL_PWREx_DisableVddUSB();

#t#t#t__HAL_RCC_PWR_CLK_DISABLE();
#t#t}
#t#telse
#t#t{
#t#t#tHAL_PWREx_DisableVddUSB();
#t#t}
[/#if]
[#-- bug 322189 DeInit End--]
    [#if dmaExist]#n#t#t/* ${ipName} DMA DeInit */
 [#assign dmaservice =service.dma]
 [#if dmaservice??]
    [#list dmaservice as dmaconfig]
        [#assign dmaCurrentRequest = dmaconfig.instanceName?lower_case]
        [#assign prefixList = dmaCurrentRequest?split("_")]
        [#list prefixList as p][#assign prefix= p][/#list]
[#assign ind=""]
            [#--workAround DFSDM--]
            [#if dmaconfig.dmaRequestName?contains("DFSDM")]
                [#assign ind=dmaconfig.dmaRequestName?replace("DFSDM","")]
            [/#if]
        [#assign ipdmahandler1 = "hdma" + prefix]
         [#-- [#if getDmaHandler(ipName)!=""][#assign ipdmahandler = getDmaHandler(ipName)][#else][#assign ipdmahandler = ipdmahandler1][/#if]--]
           [#if dmaconfig.dmaHandel??][#assign ipdmahandler = dmaconfig.dmaHandel][#else][#assign ipdmahandler = ipdmahandler1][/#if]
                [#list dmaconfig.dmaHandel as dmaH]
#t#tHAL_DMA_DeInit(${instHandler}->${dmaH}); 
                            [/#list]
    [/#list] [#-- list dmaService as dmaconfig --]
[/#if]    
    [/#if] [#-- if DMA exist --]
[#-- DeInit NVIC if DeInit --]
    [#if service??&&service.nvic??&&nvicExist&&service.nvic?size>0]#n#t#t/* ${ipName} interrupt DeInit */[#--#n#t#tHAL_NVIC_DisableIRQ([#if service.nvic.vector??]${service.nvic.vector}[/#if]);--]
[#list service.nvic as initVector]                
               [#if initVector.shared=="false"]             
#t#tHAL_NVIC_D isableIRQ(${initVector.vector});#n
                [#else]
#t/* USER CODE BEGIN ${ipName}:${initVector.vector} disable */
#t#t/**
#t#t* Uncomment the line below to disable the "${initVector.vector}" interrupt 
#t#t*        Be aware, disabling shared interrupt may affect other IPs
#t#t*/
#t#t/* HAL_NVIC_DisableIRQ(${initVector.vector}); */
#t/* USER CODE END ${ipName}:${initVector.vector} disable */
#n

                [/#if]
            [/#list]
    [/#if]

    [/#if]
#n
[/#macro]
[#-- End macro generateServiceCode --]


[#-- Function getInitServiceMode --]
[#function getInitServiceMode(ipname1, IPData)]
    [#-- assign initServicesList = {"test0":"test1"}--]
    [#assign initServicesList = ""]
        [#if IPData.halInstanceName==ipname1]
            [#assign initServicesList = {"test0":"test1"}]
            [#if IPData.initServices??]
                [#return IPData.initServices]
            [/#if]
        [/#if]
   [#return initServicesList]
[/#function]
[#-- End Function getInitServiceMode --]
[#-- --]
[#macro getMspPostInit()]
    [#assign postinitList = ""]
    [#list IPdatas as IP]  
    [#list IP.configModelList as instanceData]
    [#if instanceData.initServices??]
[#if instanceData.initServices.EnableCode??]
        [#assign GenerateNvicEnable = true]
    [/#if]
        [#if instanceData.initServices.gpioOut??]
            [#list instanceData.initCallBackInitMethodList as initCallBack]
                [#if initCallBack?contains("PostInit")]
                [#assign halMode = instanceData.halMode]
                    [#assign ipName = instanceData.ipName]
                    [#assign ipInstance = instanceData.instanceName]
                    [#if halMode!=ipName&&!ipName?contains("TIM")&&!ipName?contains("CEC")]
                        [#if !postinitList?contains(initCallBack)]
                        #nvoid ${initCallBack}(${instanceData.halMode}_HandleTypeDef *h${instanceData.halMode?lower_case});
                        [#assign postinitList = postinitList+" "+initCallBack]
                        [/#if]
                    [#else]
                        [#if !postinitList?contains(initCallBack)]
                        #nvoid ${initCallBack}([#if ipName?contains("TIM")&&!(ipName?contains("HRTIM")||ipName?contains("LPTIM"))]TIM_HandleTypeDef *htim[#else]${ipName}_HandleTypeDef *h${ipName?lower_case}[/#if]);
                        [#assign postinitList = postinitList+" "+initCallBack]
                         [/#if]
                    [/#if]
                    [#break] [#-- take only the first PostInit : case of timer--]
                [/#if]
            [/#list]
        [/#if]
    [/#if]
    [/#list]
    [/#list]
[/#macro]

[#-- --]
[#-- Function getDeInitServiceMode --]
[#function getDeInitServiceMode(ipname2, IPData)] [#--IPData = IPConfigModel --]
    [#-- assign initServicesList = {"test0":"test1"}--]
    [#assign deInitServicesList = ""]
    [#list IPData.configModelList as instanceData]
        [#if instanceData.halInstanceName==ipname2]
            [#assign deInitServicesList = {"test0":"test1"}]
            [#if instanceData.deInitServices??]
                [#return instanceData.deInitServices]
            [/#if]
        [/#if]
    [/#list]
   [#return deInitServicesList]
[/#function]
[#-- End Function getDeInitServiceMode --]

[#-- macro generateConfigCode --]
[#macro generateConfigCode ipName type serviceName instHandler tabN]
[#if type=="Init"]
 [#assign service = getInitServiceMode(ipName)]
[#else]
 [#assign service = getDeInitServiceMode(ipName)]
[/#if]
[#if serviceName=="gpio"]
    [#if service.gpio??][#assign gpioService = service.gpio][#else][#assign gpioService = ""][/#if]
[/#if]
[#if serviceName=="gpioOut"]
    [#if service.gpioOut??][#assign gpioOutService = service.gpioOut][#else][#assign gpioOutService = "empty"][/#if]
[#else]
[#assign gpioOutService = "empty"]
[/#if]
[#if serviceName=="dma" && service.dma??]
[#assign dmaService = service.dma]
[/#if]

[#if serviceName=="gpio"]
 [#assign instanceIndex =""]
    [@generateConfigModelCode configModel=gpioService inst=ipName nTab=tabN index="" mode=type/]
[/#if]
[#if serviceName=="gpioOut"]
 [#assign instanceIndex =""]
[#if gpioOutService!="empty"]
    [@generateConfigModelCode configModel=gpioOutService inst=ipName nTab=tabN index="" mode=type/]
[/#if]
[/#if]
[#if serviceName=="dma" && dmaService??]
 [#assign instanceIndex =""]
    [#list dmaService as dmaconfig] 
[#if dmaconfig.dmaRequestName=""]
            [#assign dmaCurrentRequest = dmaconfig.instanceName?lower_case]
        [#else]
            [#assign dmaCurrentRequest = dmaconfig.dmaRequestName?lower_case]
        [/#if]
[#--workAround DFSDM--]
 [#assign ind="" ]
[#if dmaCurrentRequest?contains("dfsdm")]
    [#assign ind=dmaconfig.dmaRequestName?substring(dmaconfig.dmaRequestName?length-1)]
#tif(${instHandler}->Instance == ${ipName}_Filter${ind}){
[/#if]
     [@generateConfigModelCode configModel=dmaconfig inst=ipName  nTab=tabN index="" mode=type/]
        [#assign prefixList = dmaCurrentRequest?split("_")]
        [#list prefixList as p][#assign prefix= p][/#list]

            [#-- #t__HAL_LINKDMA(${instHandler},[#if dmaconfig.dmaHandel??]${dmaconfig.dmaHandel}[#else]hdma${prefix}[/#if],hdma_${dmaconfig.instanceName?lower_case});#n --]
            [#if dmaconfig.dmaHandel?size > 1] [#-- if more than one dma handler--]
                [#assign channel="channel"]
                [#if (FamilyName=="STM32F2" || FamilyName=="STM32F4" || FamilyName=="STM32F7")]
                  [#assign channel="stream"]
                [/#if]
#t#t/* Several peripheral DMA handle pointers point to the same DMA handle.
#t#t   Be aware that there is only one ${channel} to perform all the requested DMAs. */
                [#assign one_sdio_request=false]
                [#if (FamilyName=="STM32F1" || FamilyName=="STM32F2" || FamilyName=="STM32F4") && dmaconfig.dmaRequestName=="SDIO"]
                  [#assign one_sdio_request=true]
                [/#if]
                [#if FamilyName=="STM32L1" && dmaconfig.dmaRequestName=="SD_MMC"]
                  [#assign one_sdio_request=true]
                [/#if]
                [#if (FamilyName=="STM32F7" || FamilyName=="STM32L4") && dmaconfig.dmaRequestName=="SDMMC1"]
                  [#assign one_sdio_request=true]
                [/#if]
                [#if one_sdio_request]
#t#t/* Be sure to change transfer direction before calling
#t#t   HAL_SD_ReadBlocks_DMA or HAL_SD_WriteBlocks_DMA. */
                [/#if]
            [/#if]   [#-- if more than one dma handler--]  
            [#list dmaconfig.dmaHandel as dmaH]
                [#if dmaconfig.dmaRequestName==""] [#-- if dma request name different from instanceName: case of I2S1 for example --]
#t#t__HAL_LINKDMA(${instHandler},${dmaH},hdma_${dmaconfig.instanceName?lower_case});
                [#else]
        [#--workAround DFSDM--]
            [#assign ind=""]
            [#if dmaconfig.dmaRequestName?contains("DFSDM")]
                [#assign ind=dmaconfig.dmaRequestName?replace("DFSDM","")]
            [/#if]
#t#t__HAL_LINKDMA(${instHandler},${dmaH},hdma_${dmaconfig.dmaRequestName?lower_case});
                [/#if]
            [/#list]
            [#-- #t#t__HAL_LINKDMA(${instHandler},[#if dmaconfig.dmaHandel??]${dmaconfig.dmaHandel}[#else]hdma${prefix}[/#if],hdma_${dmaconfig.instanceName?lower_case});#n --]
[#if dmaCurrentRequest?contains("dfsdm")]
#t}
[/#if]
#n
    [/#list] [#-- list dmaService as dmaconfig --]
#n
[/#if]

[/#macro]
[#-- End macro generateConfigCode --]

[#-- macro generateConfigCode --]
[#macro generateConfigCode ipName type serviceName instHandler tabN IPData1]
[#if type=="Init"]
 [#--assign service = getInitServiceMode(ipName)--]

[#else]
 [#--assign service = getDeInitServiceMode(ipName)--]
[/#if]
[#if serviceName=="gpio"]
    [#if IPData1.initServices.gpio??][#assign gpioService = IPData1.initServices.gpio][#else][#assign gpioService = ""][/#if]
[/#if]
[#if serviceName=="gpioOut"]
    [#if IPData1.initServices.gpioOut??][#assign gpioOutService = IPData1.initServices.gpioOut][#else][#assign gpioOutService = "empty"][/#if]
[#else]
[#assign gpioOutService = "empty"]
[/#if]
[#if serviceName=="dma" && IPData1.initServices.dma??]
[#assign dmaService = IPData1.initServices.dma]
[/#if]

[#if serviceName=="gpio"]
 [#assign instanceIndex =""]
    [@generateConfigModelCode configModel=gpioService inst=ipName nTab=tabN index="" mode=type/]
[/#if]
[#if serviceName=="gpioOut"]
 [#assign instanceIndex =""]
[#if gpioOutService!="empty"]
    [@generateConfigModelCode configModel=gpioOutService inst=ipName nTab=tabN index="" mode=type/]
[/#if]
[/#if]
[#if serviceName=="dma" && dmaService??]
 [#assign instanceIndex =""]
    [#list dmaService as dmaconfig] 
[#if dmaconfig.dmaRequestName=""]
            [#assign dmaCurrentRequest = dmaconfig.instanceName?lower_case]
        [#else]
            [#assign dmaCurrentRequest = dmaconfig.dmaRequestName?lower_case]
        [/#if]
#t/* ${dmaCurrentRequest?upper_case} Init */
[#--workAround DFSDM--]
 [#assign ind="" ]
[#if dmaCurrentRequest?contains("dfsdm")]
    [#assign ind=dmaconfig.dmaRequestName?substring(dmaconfig.dmaRequestName?length-1)]
#tif(${instHandler}->Instance == ${ipName}_Filter${ind}){
[/#if]
    [@generateConfigModelCode configModel=dmaconfig inst=ipName  nTab=tabN index="" mode=type/]
    [#if IPData1.usedDriver == "HAL" && dmaconfig.usedDriver == "HAL"]
        [#assign prefixList = dmaCurrentRequest?split("_")]
        [#list prefixList as p][#assign prefix= p][/#list]

            [#-- #t__HAL_LINKDMA(${instHandler},[#if dmaconfig.dmaHandel??]${dmaconfig.dmaHandel}[#else]hdma${prefix}[/#if],hdma_${dmaconfig.instanceName?lower_case});#n --]
            [#if dmaconfig.dmaHandel?size > 1] [#-- if more than one dma handler--]
                [#assign channel="channel"]
                [#if (FamilyName=="STM32F2" || FamilyName=="STM32F4" || FamilyName=="STM32F7")]
                  [#assign channel="stream"]
                [/#if]
#t#t/* Several peripheral DMA handle pointers point to the same DMA handle.
#t#t   Be aware that there is only one ${channel} to perform all the requested DMAs. */
                [#assign one_sdio_request=false]
                [#if (FamilyName=="STM32F1" || FamilyName=="STM32F2" || FamilyName=="STM32F4") && dmaconfig.dmaRequestName=="SDIO"]
                  [#assign one_sdio_request=true]
                [/#if]
                [#if FamilyName=="STM32L1" && dmaconfig.dmaRequestName=="SD_MMC"]
                  [#assign one_sdio_request=true]
                [/#if]
                [#if (FamilyName=="STM32F7" || FamilyName=="STM32L4") && dmaconfig.dmaRequestName=="SDMMC1"]
                  [#assign one_sdio_request=true]
                [/#if]
                [#if one_sdio_request]
#t#t/* Be sure to change transfer direction before calling
#t#t   HAL_SD_ReadBlocks_DMA or HAL_SD_WriteBlocks_DMA. */
                [/#if]
            [/#if]   [#-- if more than one dma handler--]  
            [#list dmaconfig.dmaHandel as dmaH]
                [#if dmaconfig.dmaRequestName==""] [#-- if dma request name different from instanceName: case of I2S1 for example --]
#t#t__HAL_LINKDMA(${instHandler},${dmaH},hdma_${dmaconfig.instanceName?lower_case});
                [#else]
            [#--workAround DFSDM--]
            [#assign ind=""]
            [#if dmaconfig.dmaRequestName?contains("DFSDM")]
                [#assign ind=dmaconfig.dmaRequestName?replace("DFSDM","")]
            [/#if] 
#t#t__HAL_LINKDMA(${instHandler},${dmaH},hdma_${dmaconfig.dmaRequestName?lower_case});

                [/#if]
            [/#list]
        [/#if]
            [#-- #t#t__HAL_LINKDMA(${instHandler},[#if dmaconfig.dmaHandel??]${dmaconfig.dmaHandel}[#else]hdma${prefix}[/#if],hdma_${dmaconfig.instanceName?lower_case});#n --]
[#if dmaCurrentRequest?contains("dfsdm")]
#t}
[/#if]
#n
    [/#list] [#-- list dmaService as dmaconfig --]
#n
[/#if]

[/#macro]
[#-- End macro generateConfigCode --]

[#function getPeriphInstanceName(periph)]
[#list configs as config]
  [#assign peripheralParams = config.peripheralParams]
  [#assign usedIPs = config.usedIPs]

  [#list usedIPs as ip]
    [#if ip=="SPI1"]
        [#if peripheralParams.get(ip)??]
        [#if peripheralParams.get(ip).get("Instance")??]        
            [#assign instance = peripheralParams.get(ip).get("Instance")]
            [#return instance]
        [#else]
            [#return "NA"]
        [/#if]
        [/#if]
    [/#if]
  [/#list]
[/#list]
[#return "not available"]
[/#function]


[#-- --]
[#macro generateConfigModelListCode2 configModel inst nTab index]
[#assign listofDeclaration = ""]
[#compress]
[#assign listofCalledMethod = ""]
[#list configModel.configs as config]
[#assign bz36245=false]
[#if config.methods??] [#-- if the pin configuration contains a list of LibMethods--]
    [#assign methodList = config.methods]
[#else] [#assign methodList = config.libMethod]
[/#if]
[#assign writeConfigComments=false]
[#list methodList as method]
[#assign errorCode = "HAL_OK"]
            [#if (method.name)?starts_with("ADV_LPBAM")]
               [#assign errorCode = "LPBAM_OK"]
            [/#if]
    [#if method.status=="OK"][#assign writeConfigComments=true][/#if]
[/#list]
[#if writeConfigComments]
[#if config.ipName?contains("CORTEX")]
[#if config.comments?? && config.comments!=""]#n#t/*#n #t* ${config.comments}#n#t */[/#if]
[#else]
[#if config.comments?? && config.comments!=""]#n#t/*#n #t* ${config.comments?replace("#t","#t")}#n#t */[/#if]
[/#if]
[/#if]
    [#list methodList as method][#assign args = ""]
            [#if method.hardCode??][#-- Hard code --]
                ${method.hardCode.text?replace("$IpInstance",inst)}
            [#else]
                [#if method.type == "Template"] [#-- Template code --]
                    [#list method.name?split("/") as n]
                        [#assign tplName = n]
                    [/#list]
                    [@optinclude name=mxTmpFolder+"/${tplName?replace('ftl','tmp')}" /]
                [/#if]
            [/#if]
            [#if method.status=="OK" && method.type != "Template" && method.type != "HardCode"]
                [#if method.arguments??]
                    [#list method.arguments as fargument][#compress]
[#if fargument.refMethod??][#-- CallLibMethod for Argument value --]
    [#assign argumentValue=""]
    [@callLibMethod CLmethod=fargument.refMethod configModelRef=configModel instRef=inst nTabRef=nTab indexRef=index argumentValue=argumentValue/]
    [#assign arg = argumentValue]
    [#if args == "" && arg!=""][#assign args = args + arg ][#else][#if arg!=""][#assign args = args + ', ' + arg][/#if][/#if]
[/#if] [#-- end if fargument.refMethod??--][#-- New --]
                    [#if fargument.addressOf] [#assign adr = "&"][#else ][#assign adr = ""][/#if]
                    [#if fargument.cast??] [#assign adr = fargument.cast + adr][/#if][/#compress]
                    [#if fargument.genericType == "struct" && fargument.argumentReference == "RefParameter"]
                        [#if fargument.optional == "output"]
                                [#assign arg = "" + adr + fargument.name]
                                [#if fargument.cast??][#assign arg = fargument.cast + arg][/#if]
                        [/#if]
                        [#if fargument.context?? && fargument.optional!="output"]
                            [#if fargument.context=="global"]
                                [#if config.ipName=="DMA" || config.ipName=="BDMA"]
                                    [#assign instanceIndex = "_"+ config.dmaRequestName?lower_case]
                                [#else]
                                    [#if config.ipName?starts_with("GPDMA") || config.ipName?starts_with("LPDMA")]
                                        [#assign instanceIndex = ""]
                                   [#else]
                                        [#-- [#assign instanceIndex = instRef?replace(name,"")]--]
                                        [#if index??][#assign instanceIndex = index][#else][#if name??][#assign instanceIndex = inst?replace(name,"")][/#if][/#if]
                                                     [#if configModel.ipName=="DFSDM" || configModel.ipName=="MDF" || configModel.ipName=="ADF"]
                                                         [#assign instanceIndex = ""]
                                                     [/#if]
                                        [/#if]
                                    [/#if]
                            [/#if]
                        [/#if]
                        [#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"][#if fargument.status!="NULL"][#assign arg = "" + adr + fargument.name + instanceIndex][#else][#assign arg = "NULL"][/#if][#else][#if  fargument.status!="NULL"][#assign arg = "" + adr + fargument.name][#else][#assign arg = "NULL"][/#if][/#if]
                        [#-- [#assign arg = "" + adr + fargument.name] --]
                        [#if ((!method.name?contains("Init")&&fargument.context=="global")||(fargument.optional=="output"))]
                        [#-- MDF : if ((!(fargument.context=="global"))||(fargument.optional=="output"))--]
                        [#else]
                            [#assign index1 =1] [#-- index of argument struct level1 --]
                        [#list fargument.argument as argument]
                            [#if argument.genericType != "struct"]
                                [#if argument.mandatory && !argument.refMethod??] 
                                [#if argument.value?? && argument.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]
                                        [#assign argValue=argument.value?replace("$Index",instanceIndex)]
                                    [#else]
                                        [#assign argValue=argument.value]
                                    [/#if][#-- if global --]
                                    [#-- Bz40086 - Begin tweak of the value in case of ADC --]
[#if ((config.name == "ADC_RegularChannelConfig" && (FamilyName!="STM32G0" || FamilyName!="STM32WL") ) || config.name == "ADC_InjectedChannelConfig" ||  ((FamilyName=="STM32G0" || FamilyName=="STM32WL" || FamilyName=="STM32U5") && config.name == "ADC_RegularChannelRankConfig")) && (FamilyName!="STM32F0" && FamilyName!="STM32L0" && FamilyName!="STM32F2" && FamilyName!="STM32F4")]                                        [#list argument?keys as k]
                                            [#if k == "name" && !(argument.value)?starts_with("ADC")]
                                                [#if argument[k] == "Rank"]                                                 
                                                    [#assign argValue="ADC_REGULAR_RANK_"+argument.value]
                                                [#elseif argument[k] == "InjectedRank"]
                                                    [#assign argValue="ADC_INJECTED_RANK_"+argument.value]
                                                [/#if]
                                            [/#if]
                                        [/#list]
                                    [/#if]                                   
                                    [#-- Bz40086 End tweak of the value in case of ADC --]
                                    [#if argument.genericType=="Array" && argument.context!="globalConst" && argument.context!="globalInit"][#-- if genericType=Array --]
                                    [#assign valList = argument.value?split(argument.arraySeparator)]     
                                            [#assign i = 0]                                  
                                        [#list valList as val]
                                            [#if argument.base == "10"]
                                                #t${argument.name}[${i}] = ${val};
                                            [#else]
                                                #t${argument.name}[${i}] = 0x${val};
                                            [/#if]
                                            [#assign i = i+1]
                                        [/#list]
                                        [#assign argValue="&"+argument.name]                                    
                                    [/#if] [#-- if genericType=Array --]
                                    [#if argument.genericType=="Array" && (argument.context=="globalConst" || argument.context=="globalInit")][#-- if genericType=Array and gloabl--]                                        
                                        [#assign argValue="("+argument.typeName +" *)"+argument.name]
                                    [/#if]
                                    [#if argument.value!="" && argument.value!="N/A"]
                                    [#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"][#assign varName=fargument.name +"." +instanceIndex][#else][#assign varName=fargument.name][/#if]
                                        [#assign indicator = varName+"."+argument.name+" = "+argValue+" "]
                                        [#assign indicatorName = varName+"."+argument.name]
                                        [#if !listofDeclaration?contains(indicator)][#-- if not repeted --]
                                            [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"][#assign varName=fargument.name +"." +instanceIndex]${fargument.name}${instanceIndex}[#else][#assign varName=fargument.name]${fargument.name}[/#if].${argument.name} = ${argValue};
                                            [#assign listofDeclaration = listofDeclaration?replace(indicatorName+" =","")]
                                            [#assign listofDeclaration = listofDeclaration +", "+ varName+"."+argument.name+" = "+argValue+" "]                                                                                 
                                        [/#if]
                                    [#else]
                                    [#if nTab==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global" && fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = [#if argument.value!="N/A"]${argValue}[/#if];
                                    [/#if]                                                                     
                                    [/#if]
                                    [#else] [#-- else argument.mandatory--]
                                      [#if fargument.name!="GPIO_InitStruct" && fargument.name!="GPIO_Init"]
                                            [#if argument.name=="Instance"][#-- if argument=Instance--]
                                              [#-- calculate the value of Instance argument if contains $Index --]
                                                [#if  (argument.value??&& argument.value!="__NULL") && (argument.value?contains("$Index"))]
                                                    [#assign instanceValue=argument.value?replace("$Index",index)]
[#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name +instanceIndex][#else][#assign varName=fargument.name][/#if]
                                                    [#assign indicator = varName+"."+argument.name+" = "+instanceValue+" "]
                                                    [#if !listofDeclaration?contains(indicator)]    [#-- if not repeted --]
                                                    [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = ${instanceValue};
                                                            [#assign listofDeclaration = listofDeclaration +", "+ indicator]
                                                    
                                                    [/#if]
                                                [#else]
[#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name+instanceIndex][#else][#assign varName=fargument.name][/#if] [#if argument.value?? && argument.value!="__NULL"][#assign argv =argument.value][#else][#assign argv=inst][/#if]
                                                   [#assign indicator = varName+"."+argument.name+" = "+argv+" "]
                                                   [#if !listofDeclaration?contains(indicator)] [#-- if not repeted --]
                                                    [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = [#if argument.value?? && argument.value!="__NULL"]${argument.value};[#else]${inst};[/#if]
                                                            [#assign listofDeclaration = listofDeclaration +", "+ indicator]
                                                            [#if index1 == fargument.argument?size]
                                                                #n
                                                            [/#if]
                                                            [#if configModel.ipName=="RTC" && config.name=="RTC_Init_Only"]
                                                                [#list configModel.configs as bz36245config]
                                                                    [#if bz36245config.name=="RTC_Init"]
                                                                        [#assign bz36245=true]
                                                                    [/#if]
                                                                [/#list]
                                                            [/#if]
                                                            [#if bz36245]                                                              
                                                            [/#if]
                                                   [/#if]
                                                [/#if]
                                          [#else]
                                              [#if argument.status=="KO"]
                                                   [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"]//${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = ${argument.value};                                        
                                              [/#if]
                                              [#if argument.value?? && argument.value!="__NULL"]

[#if argument.refMethod??] [#-- CallLibMethod for Argument value --]
    [#assign argumentValue=""]
    [@callLibMethod CLmethod=argument.refMethod configModelRef=configModel instRef=inst nTabRef=nTab indexRef=index argumentValue=argumentValue/]
    [#assign argTmp = argumentValue]
[/#if] [#-- end if fargument.refMethod??--] [#-- New --]
                [#if argument.value!="N/A"]
                                                        [#if argument.refMethod??][#assign argValue=argumentValue][#else][#assign argValue=argument.value][/#if]
                                                        [#if instanceIndex??&&fargument.context=="global"][#assign varName=fargument.name+instanceIndex][#else][#assign varName=fargument.name][/#if]
                                                        [#assign indicator = varName+"."+argument.name+" = "+argValue+" "]
                                                        [#assign indicatorName = varName+"."+argument.name]
                                                        [#if !listofDeclaration?contains(indicator)][#-- if not repeted --] 
                                                            [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name +"." +instanceIndex]${fargument.name}${instanceIndex}[#else][#assign varName=fargument.name]${fargument.name}[/#if].${argument.name} = ${argValue};
                                                            [#assign listofDeclaration = listofDeclaration?replace(indicatorName+" =","")]
                                                            [#assign listofDeclaration = listofDeclaration +", "+ varName+"."+argument.name+" = "+argValue+" "]                                                                                 
                                                        [/#if]
                                                    [/#if]
                                              [/#if]                                    
                                          [/#if][#-- if argument=Instance--]                                
                                      [/#if]    
                                [/#if][#-- if argument.mandatory--]     
                            [#else]
                            [#assign index2=0]
[#list argument.argument as argument2]
			[#if argument2.genericType!="struct"]
[#if config.ipName=="ETH"]
                                [#if argument2.value??][#assign argValue=argument2.value][#else] [#assign argValue=""][/#if]
                                [#if argument2.mandatory]
                                    [#if argument2.value??]
                                    [#if instanceIndex??&&fargument.context=="global"][#assign argValue=argument2.value?replace("$Index",instanceIndex)][#else][#assign argValue=argument2.value][/#if]
                                    [#if argument2.genericType=="Array"][#-- if genericType=Array --] 
                                        [#assign valList = argument2.value?split(":")]     
                                            [#assign i = 0]                                  
                                        [#list valList as val] 
                                            [#if argument2.typeName == "10"]
                                                #t${argument2.name}[${i}] = ${val};
                                            [#else]
                                                #t${argument2.name}[${i}] = 0x${val};
                                            [/#if]                                            [#assign i = i+1]
                                        [/#list]
                                        [#assign argValue="&"+argument2.name+"[0]"]
                                    [/#if] [#-- if genericType=Array --]
                                    [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name} = ${argValue};                                    
                                    [/#if]
                               [#else] [#-- !argument.mandatory --]
                                    [#if argument2.status=="KO"]
                                        [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]//${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name} = ${argValue};
                                    [/#if]
                                    [#if argument2.status=="OK"]
                                    [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name} = ${argValue};
                                    [/#if]
[/#if]
                                [/#if][#-- if argument.mandatory --]
[#if config.ipName!="ETH"]
                                [#if argument2.value?? && argument2.value!="__NULL"][#assign argValue=argument2.value][#else] [#assign argValue=""][/#if]
                                [#if argument2.mandatory]
                                    [#if argument2.value?? && argument2.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign argValue=argument2.value?replace("$Index",instanceIndex)][#else][#assign argValue=argument2.value][/#if]
                                    [#if argument2.genericType=="Array" && argument2.context!="globalConst" && argument2.context!="globalInit"][#-- if genericType=Array --]
                                        [#if argument2.arraySeparator?? && argument2.arraySeparator!=""]
                                        [#assign valList = argument2.value?split(argument2.arraySeparator)]     
                                        [#else]
                                            [#assign valList = argument2.value?split(":")]
                                        [/#if]
                                            [#assign i = 0]
                                            [#assign argValue="&"+argument2.name+"[0]"]
                                            [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name +instanceIndex][#else][#assign varName=fargument.name][/#if]
                                        [#list valList as val]
                                            [#if nTab==2]#t#t[#else]#t[/#if][#t]
                                            [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#t]
                                                ${fargument.name}${instanceIndex}[#t]
                                            [#else]
                                                ${fargument.name}[#t]
                                            [/#if]
                                            .${argument.name}.${argument2.name}[${i}] =[#t]
                                            [#if argument2.base == "10"]
                                                #t${val};
                                            [#else]
                                                #t0x${val};
                                            [/#if]
                                          [#assign i = i+1]
                                        [/#list]
                                            [#if index2 == argument.argument?size]
                                                 [#-- add space line at the end of argument setting --]
                                            [/#if]
                                    [#else] [#-- if genericType=Array --]
                                    [#-- if argument is a global array --]
                                    [#if argument2.genericType=="Array" && (argument2.context=="globalConst" || argument2.context=="globalInit")][#-- if genericType=Array and gloabl--]                                        
                                        [#assign argValue="("+argument2.typeName +" *)"+argument2.variableName]
                                    [/#if]                                         
                                    [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name +instanceIndex][#else][#assign varName=fargument.name][/#if]
                                                    [#assign indicatorName = varName+"."+argument.name+"."+argument2.name]
                                                    [#assign indicator = varName+"."+argument.name+"."+argument2.name+" = "+argValue+" "]
                                                    [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]
                                                        [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name} = ${argValue};                                    

                                                        [#if index2 == argument.argument?size]
                                                            #n [#-- add space line at the end of argument setting --] 
                                                        [/#if]
                                                            [#assign listofDeclaration = listofDeclaration?replace(indicatorName+" =","")]
                                                            [#assign listofDeclaration = listofDeclaration +", "+ indicator]
                                                    [/#if]
                                        [/#if]
                                    [/#if]
                               [#else] [#-- !argument.mandatory --]
                                    [#if argument2.status=="WARNING"]
                                        [#if argument2.name=="ShieldIOs"]
                                            [#assign argValue ="0"]
                                            [#assign indicatorName = varName+"."+argument.name+"."+argument2.name]
                                            [#assign indicator = varName+"."+argument.name+"."+argument2.name+" = "+argValue+" "]
                                            [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]
                                                [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name} = ${argValue};                                    
                                               [#if index2 == argument.argument?size]
                                                        #n [#-- add space line at the end of argument setting --]
                                                [/#if]
                                            [/#if]
                                        [/#if]
                                    [/#if]
                                    [#if argument2.status=="KO"]
                                        [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"]//${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name} = ${argValue};
                                    [/#if]
                                    [#if argument2.status=="OK"]
[#if instanceIndex??&&fargument.context=="global"][#assign varName=fargument.name +instanceIndex][#else][#assign varName=fargument.name][/#if]
                                         [#assign indicatorName = varName+"."+argument.name+"."+argument2.name]
                                         [#assign indicator = varName+"."+argument.name+"."+argument2.name+" = "+argValue+" "]
                                         [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]   
                                            [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name} = ${argValue};
                                            [#assign listofDeclaration = listofDeclaration?replace(indicatorName+" =","")]
                                            [#assign listofDeclaration = listofDeclaration +", "+ indicator]                                            
                                         [/#if]
                                    [/#if]

[/#if]
                                [/#if][#-- if argument.mandatory --]
[#else]
[#list argument2.argument as argument3]
    [#if argument3.genericType!="struct"]
        [#if argument3.value?? && argument3.value!="__NULL"][#assign argValue=argument3.value][#else] [#assign argValue=""][/#if]
                                [#if argument3.mandatory]
                                    [#if argument3.value?? && argument3.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign argValue=argument3.value?replace("$Index",instanceIndex)][#else][#assign argValue=argument3.value][/#if]
                                    [#if argument3.genericType=="Array" && argument3.context!="globalConst" && argument3.context!="globalInit"][#-- if genericType=Array --] 
                                        [#if argument3.arraySeparator?? && argument3.arraySeparator!=""]
                                            [#assign valList = argument3.value?split(argument3.arraySeparator)]     
                                        [#else]
                                            [#assign valList = argument3.value?split(":")]
                                        [/#if]
                                            [#assign i = 0]                                  
                                        [#list valList as val] 
                                            [#if argument3.base == "10"]
                                                #t${argument3.name}[${i}] = ${val};
                                            [#else]
                                                #t${argument3.name}[${i}] = 0x${val};
                                            [/#if]
                                            [#assign i = i+1]
                                        [/#list]
                                        [#assign argValue="&"+argument3.name+"[0]"]
                                    [/#if] [#-- if genericType=Array --]
                                     [#-- if argument is a global array --]
                                    [#if argument3.genericType=="Array" && (argument3.context=="globalConst"||argument3.context=="globalInit")][#-- if genericType=Array and gloabl--]                                        
                                        [#assign argValue="("+argument3.typeName +" *)"+argument3.name]
                                    [/#if]
[#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name +instanceIndex][#else][#assign varName=fargument.name][/#if]
                                         [#assign indicatorName = varName+"."+argument.name+"."+argument2.name+"."+argument3.name]
                                         [#assign indicator = varName+"."+argument.name+"."+argument2.name+"."+argument3.name+" = "+argValue+ " "]
                                         [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]                                      
                                            [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name}.${argument3.name} = ${argValue};                                    
                                            [#assign listofDeclaration = listofDeclaration?replace(indicatorName+" =","")]
                                            [#assign listofDeclaration = listofDeclaration +", "+ indicator]
                                         [/#if]                                       [/#if]
                               [#else] [#-- !argument.mandatory --]
                                    [#if argument3.status=="KO"]
[#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name +instanceIndex][#else][#assign varName=fargument.name][/#if]
                                         [#assign indicatorName = varName+"."+argument.name+"."+argument2.name+"."+argument3.name]
                                         [#assign indicator = varName+"."+argument.name+"."+argument2.name+"."+argument3.name+" = "+argValue+" "] 
                                         [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]  
                                            [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name}.${argument3.name} = ${argValue};
                                            [#assign listofDeclaration = listofDeclaration?replace(indicatorName+" =","")]
                                            [#assign listofDeclaration = listofDeclaration +", "+ indicator]
                                         [/#if]
                                    [/#if]
                                    [#if argument3.status=="OK"]
[#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name +instanceIndex][#else][#assign varName=fargument.name][/#if]
                                         [#assign indicatorName = varName+"."+argument.name+"."+argument2.name+"."+argument3.name]
                                         [#assign indicator = varName+"."+argument.name+"."+argument2.name+"."+argument3.name+" = "+argValue+" "] 
                                         [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]  
                                            [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name}.${argument3.name} = ${argValue};
                                            [#assign listofDeclaration = listofDeclaration?replace(indicatorName+" =","")]
                                            [#assign listofDeclaration = listofDeclaration +", "+ indicator]
                                        [/#if]
                                    [/#if]
                                [/#if][#-- if argument.mandatory --]
    [#else]
		[#list argument3.argument as argument4]
			[#if argument4.genericType!="struct"]
				[#if argument4.value?? && argument4.value!="__NULL"][#assign argValue=argument4.value][#else] [#assign argValue=""][/#if]
				[#if argument4.value?? && argument4.value!="__NULL"]
					[#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name +instanceIndex][#else][#assign varName=fargument.name][/#if]
                    [#assign indicatorName = varName+"."+argument.name+"."+argument2.name+"."+argument3.name+"."+argument4.name]
                    [#assign indicator = varName+"."+argument.name+"."+argument2.name+"."+argument3.name+"."+argument4.name+" = "+argValue+" "] 
                    [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]  
                        [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name}.${argument3.name}.${argument4.name} = ${argValue};                                    
                        [#assign listofDeclaration = listofDeclaration?replace(indicatorName+" =","")]
                        [#assign listofDeclaration = listofDeclaration +", "+ indicator]
                    [/#if]
				[/#if]
			[#else]
				[#list argument4.argument as argument5]
					[#if argument5.genericType!="struct"]
						[#if argument5.value?? && argument5.value!="__NULL"][#assign argValue=argument5.value][#else] [#assign argValue=""][/#if]
						[#if argument5.value?? && argument5.value!="__NULL"]
                            [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign varName=fargument.name +instanceIndex][#else][#assign varName=fargument.name][/#if]
                            [#assign indicatorName = varName+"."+argument.name+"."+argument2.name+"."+argument3.name+"."+argument4.name+"."+argument5.name]
                            [#assign indicator = varName+"."+argument.name+"."+argument2.name+"."+argument3.name+"."+argument4.name+"."+argument5.name+" = "+argValue+" "] 
                            [#if !listofDeclaration?contains(indicator)]  [#-- if not repeted --]  
                                [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument2.name}.${argument3.name}.${argument4.name}.${argument5.name} = ${argValue};                                    
                                [#assign listofDeclaration = listofDeclaration?replace(indicatorName+" =","")]
                                [#assign listofDeclaration = listofDeclaration +", "+ indicator]
                            [/#if]
						[/#if]
					[/#if]
				[/#list]
			[/#if]
		 [/#list]
    [/#if]                                
[/#list]
[/#if]
[#assign index2=index2 + 1]
                            [/#list]
                            [/#if]
[#assign index1 =index1 + 1]
                        [/#list][#-- list  fargument.argument as argument--]
                        [/#if]
                    [#else][#-- if fargument a simple type struct --]
                        [#if fargument.genericType=="Array"][#-- if genericType=Array --]
                            [#if fargument.context!="globalConst" && fargument.context!="globalInit"]
                                [#assign valList = fargument.value?split(fargument.arraySeparator)]
                                [#assign i = 0]
                                [#list valList as val]
                                    [#if fargument.base == "10"]
                                        #t${fargument.name}[${i}] = ${val};
                                    [#else]
                                        #t${fargument.name}[${i}] = 0x${val};
                                    [/#if]
                                    [#assign i = i+1]
                                [/#list]
                            [/#if]
                            [#if fargument.status!="NULL"]
                                [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"]
                                    [#assign arg = "" + adr + fargument.name + instanceIndex]
                                [#else]
                                    [#assign arg = "" + adr + fargument.name]
                                [/#if]
                            [#else]
                                [#assign arg = "NULL"]
                            [/#if]
                        [#else] [#-- if genericType=Array --]
                    [#assign arg = ""]
                        [#if fargument.status=="OK" && fargument.value?? && fargument.value!="__NULL" && fargument.argumentReference == "RefParameter"]
                            [#if name??][#assign argIndex = inst?replace(name,"")]  [/#if]
                                            [#if argIndex??] 
                                                [#assign argValue=fargument.value?replace("$Index",argIndex)]
                                                [#if fargument.returnValue!="true"]
                                                    [#assign arg = "" + adr + argValue]
                                                [/#if]
                                            [#else]
                                                [#if fargument.returnValue!="true"]
                                                    [#assign arg = "" + adr + fargument.value]                                                
                                                [/#if]
                                            [/#if]    
                        [#else] 
                            [#if fargument.status=="NULL"][#assign arg = "" + adr + "NULL"] [/#if]      
                    [/#if]
                        [/#if] [#-- if genericType=Array --]
                    [/#if] [#-- end if fargument is struct --]
                    [#if args == "" && arg!=""][#assign args = args + arg ][#else][#if arg!=""][#assign args = args + ', ' + arg][/#if][/#if]
                    [/#list]
                    [#assign retval=""]
            [#list method.arguments as argument]
            [#if argument.returnValue=="true"]
                [#assign retval=argument.name]
            [/#if]
            [/#list]
[#if !(method.callMethod) || (S_FATFS_SDIO?? && (inst=="SDIO" || inst?starts_with("SDMMC")) && !(method.name=="HAL_RCCEx_PeriphCLKConfig"))] [#-- if HAL_SD_Init  and SDIO is used with FATFS--]
[#else]		    
                [#if inst?contains("ETH")]
                    #n
                    #t/* USER CODE BEGIN MACADDRESS */
                    #t#t
                    #t/* USER CODE END MACADDRESS */
                    #n
                [/#if]
[#--[#if nTab==2]#t#t[#else]#t[/#if]${method.name}(${args});#n--]
        [#if method.returnHAL=="false"]
            [#-- Check if Method is already called (listofCalledMethod)--]
            [#assign methodName = method.name + "("+args+")"]
            [#if !listofCalledMethod?contains(methodName)]
                [#if nTab==2]#t#t[#else]#t[/#if]${method.name}(${args});
                [#if method.optimizale??&&method.optimizale==true]
                [#assign listofCalledMethod = listofCalledMethod + ", "+ methodName]
                [/#if]
            [#if bz36245]
             }
               [/#if]
            [/#if]
        [#else]
            [#-- [#if nTab==2]#t#t[#else]#t[/#if]${method.name}(${args});#n --]
            [#-- Check if Method is already called (listofCalledMethod)--]
            [#assign methodName = method.name + "("+args+")"] 
            [#if !listofCalledMethod?contains(methodName) && method.optimizale??]
                [#-- specific case for I2C setData fucntion --]
                [#if method.name?contains("ADV_LPBAM_I2C") &&(method.name?contains("_SetDataQ") || method.name?contains("_SetFullQ"))]
                   [#assign Sarg = args?split(',')]
                       [#if Sarg??]
                        [#assign sizeArg= Sarg[2]?replace(" &","")]
                       [#else]
                        [#assign sizeArg= "pRxData_I2C"]
                       [/#if]           
                    #t/* Set transfer parameters */
                    #tdata_size = ${sizeArg}.Size;
                    #ttransfer_idx = 0;
                    #n
                    #t/* Repeat inserting I2C master Tx data queue untill completing all data */
                    #twhile (${sizeArg}.Size != 0U)
                    #t{
                    #t#tif (${method.name}(${args}) != [#if method.returnHAL == "true"]${errorCode}[#else]${method.returnHAL}[/#if])                
                    #t#t{
                    #t#t#tError_Handler();                    
                    #t#t}
                    #n       
                    #t#ttransfer_idx++;
                    #t#tif (data_size > LPBAM_I2C_MAX_DATA_SIZE)
                    #t#t{
                      #t#t#tdata_size -= LPBAM_I2C_MAX_DATA_SIZE;
                    #t#t}
                    #t#telse
                    #t#t{
                      #t#tdata_size = 0U;
                    #t#t}
                    #n
                    #t#t${sizeArg}.Size = data_size;
                    #t}
                [#else]
                    [#if nTab==2]#t#t[#else]#t[/#if]if (${method.name}(${args}) != [#if method.returnHAL == "true"]${errorCode}[#else]${method.returnHAL}[/#if])                
                    [#if nTab==2]#t#t[#else]#t[/#if]{
                    [#if nTab==2]#t#t[#else]#t[/#if]#tError_Handler();                    
                    [#if nTab==2]#t#t[#else]#t[/#if]}
                [/#if]
                [#if method.optimizale??&&method.optimizale==true]
                [#assign listofCalledMethod = listofCalledMethod + ", "+ methodName]
                [/#if]
            [/#if]
        [/#if]
[/#if]                   
            [#else]
                    [#if !(method.callMethod) || (S_FATFS_SDIO?? && (inst=="SDIO" || inst?starts_with("SDMMC")))] [#-- if HAL_SD_Init  and SDIO is used with FATFS--][#else]
                        [#--[#if nTab==2]#t#t[#else]#t[/#if]${method.name}();#n--]
                        [#if method.returnHAL=="false"]
            [#if nTab==2]#t#t[#else]#t[/#if]${method.name}();
                        [#else]
                            [#-- [#if nTab==2]#t#t[#else]#t[/#if]${method.name}(${args});#n --]
                            [#if nTab==2]#t#t[#else]#t[/#if]if (${method.name}() != [#if method.returnHAL == "true"]${errorCode}[#else]${method.returnHAL}[/#if])
                            [#if nTab==2]#t#t[#else]#t[/#if]{
                            [#if nTab==2]#t#t[#else]#t[/#if]#tError_Handler();
                            [#if nTab==2]#t#t[#else]#t[/#if]}
                        [/#if]                 
                    [/#if]
                [/#if]			
        [/#if]
        [#if method.status=="KO"]
        #n [#if nTab==2]#t#t[#else]#t[/#if]//!!! ${method.name} is commented because some parameters are missing
            [#if method.arguments??]			
                [#list method.arguments as fargument]
                    [#if fargument.addressOf] [#assign adr = "&"][#else ] [#assign adr = ""][/#if]
                    [#if fargument.cast??] [#assign adr = fargument.cast + adr][/#if]
                    [#if fargument.genericType == "struct"][#assign arg = "" + adr + fargument.name]
                                        [#if fargument.context??]                   
                                            [#if fargument.context=="global"]
                                                [#if config.ipName=="DMA" || config.ipName=="BDMA" || config.ipName=="BDMA1"]
                                                [#assign instanceIndex = "_"+ config.dmaRequestName?lower_case]
                                                [#else]
                                               [#if name??] [#assign instanceIndex = inst?replace(name,"")][/#if]
                                                [#if configModel.ipName=="DFSDM" || configModel.ipName=="MDF" || configModel.ipName=="ADF"]
                                                    [#assign instanceIndex = ""]
                                                [/#if]                
                                                [/#if]
                                            [/#if]
                                        [/#if]              
                        [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign arg = "" + adr + fargument.name + instanceIndex][#else][#assign arg = "" + adr + fargument.name][/#if]
                        [#if (!method.name?contains("Init")&&fargument.context=="global")]
        [#-- MDF  --]
                        [#else]
                        [#list fargument.argument as argument]	
                                [#if argument.genericType != "struct"]
                                [#if argument.mandatory && argument.value?? && argument.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign argValue=argument.value?replace("$Index",instanceIndex)][#else][#assign argValue=argument.value][/#if]
                                    [#if nTab==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = ${argValue};
                                 [#else]
                                    [#if argument.name=="Instance"]
                                        [#if nTab==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = ${inst};
                                    [/#if]                                
                                [/#if]
                            [#else]
                            [#list argument.argument as argument1]
                                [#if argument1.mandatory && argument1.value?? && argument1.value!="__NULL"]
                                    [#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"][#assign argValue=argument1.value?replace("$Index",instanceIndex)][#else][#assign argValue=argument1.value][/#if]
                                [#if nTab==2]#t#t[#else]#t[/#if]//[#if instanceIndex??&&fargument.context=="global"&& fargument.optional!="output"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name}.${argument1.name} = ${argValue};
                                [/#if]
                            [/#list]
                            [/#if]
                            [/#list]
[/#if]
                                        [#else] [#-- if argument != struct --]
 [#if name??][#assign argIndex = inst?replace(name,"")]  
                                            [#assign argIndex = inst?replace(name,"")] 
[/#if]
                                            [#if argIndex??]
                                                [#assign argValue=fargument.value?replace("$Index",argIndex)]
                                                [#assign arg = "" + adr + argValue]
                                            [#else]
                                                [#assign arg = "" + adr + fargument.value]                                                
                                            [/#if]
                                        [/#if]
                    [#if args == ""][#assign args = args + arg ]
                    [#else][#assign args = args + ', ' + arg]
                                        [/#if]
                                [/#list]
                                [#if nTab==2]#t#t[#else]#t[/#if]#t//${method.name}(${args});
                        [#else] [#-- if method without argument --]
                            [#if method.returnHAL=="false"]
                            [#if nTab==2]#t#t[#else]#t[/#if]${method.name}();
                            [#else]
                                [#-- [#if nTab==2]#t#t[#else]#t[/#if]${method.name}(${args});#n --]
                                [#if nTab==2]#t#t[#else]#t[/#if]if (${method.name}() != [#if method.returnHAL == "true"]${errorCode}[#else]${method.returnHAL}[/#if])
                                [#if nTab==2]#t#t[#else]#t[/#if]{
                                [#if nTab==2]#t#t[#else]#t[/#if]#tError_Handler();
                                [#if nTab==2]#t#t[#else]#t[/#if]}
                            [/#if]
                               [#--[#if nTab==2]#t#t[#else]#t[/#if]${method.name}();--]
                        [/#if]
                [/#if]
        [/#list]
[#-- assign instanceIndex = "" --]
 [#-- else there is no LibMethod to call--]
[#if bz36245]                                                           
    #n
    #t/* USER CODE BEGIN Check_RTC_BKUP */
    #t#t
    #t/* USER CODE END Check_RTC_BKUP */
    #n
[/#if]
[/#list]
[/#compress]
[/#macro]
[#-- End macro generateConfigModelListCode2 --]
